메뉴 건너뛰기

프로그램언어

조회 수 30447 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
htmlentities해당하는 모든 문자를 HTML 엔티티로 변환
 
string htmlentities ( string $string [, int $quote_style [, string $charset [, bool $double_encode ]]] )

htmlentities()는 HTML 문자 엔티티에 존재하는 모든 문자를 엔티티로 변환하는 점을 제외하면, htmlspecialchars()와 완전히 동일합니다.

디코드(역변환)하려면 html_entity_decode()를 사용할 수 있습니다.
 
Example #1 htmlentities() ------------------------------------------------------------------------------------
<?php
$str 
"A 'quote' is <b>bold</b>"
;

// 출력: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str
);

// 출력: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($strENT_QUOTES);
?>

--------------------------------------------------------------------------------------------------------------
 
html_entity_decode모든 HTML 엔티티를 해당하는 문자로 변환
 
string html_entity_decode ( string $string [, int $quote_style [, string $charset ]] )

html_entity_decode()string 의 모든 HTML 엔티티를 해당하는 문자로 변환합니다. htmlentities()의 역함수입니다.

 

Example #1 HTML 엔티티 디코딩---------------------------------------------------------------------------------
<?php
$orig 
"I'll \"walk\" the <b>dog</b> now"
;
$a htmlentities($orig
);
$b html_entity_decode($a
);
echo 
$a
// I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now
echo $b
// I'll "walk" the <b>dog</b> now

// PHP 4.3.0 이전 사용자는 이렇게 할 수 있습니다:
function unhtmlentities($string
)
{
    
// 숫자 엔티티 치환
    
$string preg_replace('~&#x([0-9a-f]+);~ei''chr(hexdec("\\1"))'$string
);
    
// 문자 엔티티 치환
    
$trans_tbl get_html_translation_table(HTML_ENTITIES
);
    
$trans_tbl array_flip($trans_tbl
);
    return 
strtr($string$trans_tbl
);
}
$c unhtmlentities($a
);
echo 
$c
// I'll "walk" the <b>dog</b> now
?>
----------------------------------------------------------------------------------------------------------------
 Note: trim(html_entity_decode('&nbsp;'));는 문자열을 빈 문자열로 변환하지 않습니다. 이는 기본값인 ISO-8859-1 문자셋에서 '&nbsp;' 엔티티가 (trim()에서 잘라내는) 아스키 코드 32

List of Articles
번호 제목 날짜 조회 수
60 JSON and JavaScript usage 2014.03.26 19064
59 jquery 이용 아이디 중복체크 실시간 2014.04.12 20341
58 jQuery 개발자를 위한 메모 - 플러그 인 2014.03.26 19257
57 jQuery 개발자를 위한 메모 - 레퍼런스 2014.03.26 19522
56 JAVASCRIPT 차트, 그래프 모음 (php chart, graph ) 2021.03.26 1618
55 Javascript 두 좌표 사이의 거리 구하기, 두 좌표의 중앙 좌표 구하기 file 2020.09.23 535
54 is_array — 변수가 배열인지 확인 2016.12.23 18048
53 input 자동완성기능 끄기 2019.02.19 1217
52 ini_get - php.ini에 지정되어 있는 지시어의 값을 읽어온다 2016.12.23 19520
51 include 와 namespace 2019.01.08 1099
50 implode — 문자열로 배열 원소를 결합 2016.12.23 19951
49 iframe 사용시 iframe의 높이가 내용의 높이만큼 자동으로 조절 2014.04.12 21862
48 http://홈주소/?mode=xxx 하는방법 2017.03.07 17642
47 HTTP 인증하기, 로그인창 띄우기 file 2021.03.26 214
46 HTTP Protocol의 data method - GET / POST 2016.04.22 20637
» htmlentities <-> html_entity_decode (엔티티 2014.04.12 30447
44 HEREDOC <<< ( PHP에서 echo로 HTML쉽게 표시하기 ) 2021.03.26 371
43 headers_sent 헤더 전송 여부를 확인 2016.12.23 19409
42 glob 현재 디렉토리에서 pattern에 일치하는 경로 이름을 배열로 반환 2016.12.23 19636
41 GD를 이용한 스팸성 게시물 차단을 위한 보안 단어 입력 예제 2014.02.27 26945
Board Pagination Prev 1 ... 8 9 10 11 12 13 14 15 16 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved