[ php ] htmlspecialchars 와 json 의 관계 > php

본문 바로가기

사이트 내 전체검색

php

[ php ] htmlspecialchars 와 json 의 관계

작성일 19-12-04 01:40

페이지 정보

작성자 웹지기 조회 7,633회 댓글 1건

본문

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 &#xFFFD; (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 &#xFFFD; (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로 넘어온 값에 대하여 역으로 풀어주는 방법이 있다.

 

 


추천1

비추천 0

댓글목록

장승원님의 댓글

profile_image 장승원
작성일

htmlspecialchars에서 5가지가 변경 된다고 나와있지만 실제로 get으로 값을 전송하게 되면
[ 괄호 열기, ] 괄호 닫기, &, 그리고 띄어쓰기 같은 경우도 모두 변경이 되어서
htmlspecialchars 이녀석을 사용하면 여기저기 손을 봐야 하는곳이 굉장히 많아서
그냥 닫아버리고 다른 방법을 간구 했습니다.

전체 82건 1 페이지

이미지 목록

게시물 검색
Copyright © 즐거운 코딩 생활 ( funyphp ). All rights reserved.
PC 버전으로 보기