htmlspecialchars는 특수문자를 HTML 엔티티로 변환해준다.
수행되는 번역
Character | Replacement |
---|---|
& (ampersand) | & |
" (double quote) | ", unless
ENT_NOQUOTES
is set |
' (single quote) | ' (for
ENT_HTML401
) or ' (for
ENT_XML1
,
ENT_XHTML
or
ENT_HTML5
), but only when
ENT_QUOTES
is set |
< (less than) | < |
> (greater than) | > |
사용가능한 상수
Constant Name | Description |
---|---|
ENT_COMPAT
|
Will convert double-quotes and leave single-quotes alone. |
ENT_QUOTES
|
Will convert both double and single quotes. |
ENT_NOQUOTES
|
Will leave both double and single quotes unconverted. |
ENT_IGNORE
|
Silently discard invalid code unit sequences instead of returning an empty string. Using this flag is discouraged as it » may have security implications. |
ENT_SUBSTITUTE
|
Replace invalid code unit sequences with a Unicode Replacement Character U+FFFD (UTF-8) or � (otherwise) instead of returning an empty string. |
ENT_DISALLOWED
|
Replace invalid code points for the given document type with a Unicode Replacement Character U+FFFD (UTF-8) or � (otherwise) instead of leaving them as is. This may be useful, for instance, to ensure the well-formedness of XML documents with embedded external content. |
ENT_HTML401
|
Handle code as HTML 4.01. |
ENT_XML1
|
Handle code as XML 1. |
ENT_XHTML
|
Handle code as XHTML. |
ENT_HTML5
|
Handle code as HTML 5. |
그러므로 이함수를 활성화해서 사용하는경우 json으로 변환되는 값은 " 를 사용하므로
이 값들을 무시하게 해주어야 한다.
즉 POST, GET, REQUEST 등으로 넘어오는 값에 변경해야할 문자가 존재하면 모두 변경해 버림으로
json값 자체에 번역되어 들어오는 값으로 인식이 되어 정상적인 처리가 되지 않는다.
해경방법은
# htmlspecialchars($data, ENT_NOQUOTES);
와 같이 사용하여 값을 넘겨주는 방법과
# $menudata_json = htmlspecialchars_decode($this->input->post('menudata'));
이처럼 post로 넘어온 값에 대하여 역으로 풀어주는 방법이 있다.
LIST
'WEBD > PHP' 카테고리의 다른 글
Class 사용법 정리 3. 클래스상속 (0) | 2020.10.02 |
---|---|
Class 사용법 정리 2. 객체생성 (0) | 2020.10.02 |
Class 사용법 정리 1. 클래스 정의 (0) | 2020.10.02 |
php에서 mysql 버젼 확인 하기 (0) | 2020.10.02 |
MS Word docx 파일 생성 라이브러리 (0) | 2020.10.02 |