PHP html_entity_decode() 함수
예제
HTML 엔티티를 문자로 변환합니다:
<?php $str = "<© W3Sçh°°¦§>"; echo html_entity_decode($str); ?>
위 코드의 HTML 출력은 다음과 같습니다. (원본 코드 확인):
<!DOCTYPE html> <html> <body> <? W3S?h????> </body> </html>
위 코드의 브라우저 출력:
<? W3S?h????>
정의와 사용법
html_entity_decode() 함수는 HTML 엔티티를 문자로 변환합니다.
html_entity_decode() 함수는 htmlentities() 함수의 반대 함수.
문법
html_entity_decode(string,flags,character-set)
파라미터 | 설명 |
---|---|
string | 필수. 디코딩할 문자열을 지정 |
flags |
선택적. 괄호 처리 방식 및 사용할 문서 타입을 지정 사용 가능한 괄호 유형:
사용할 문서 타입의 추가 flags를 지정
|
character-set |
선택적. 문자열 값, 사용할 문자셋을 지정 허용된 값:
注释:在 PHP 5.4 之前的版本,无法被识别的字符集将被忽略并由 ISO-8859-1 替代。自 PHP 5.4 起,无法被识别的字符集将被忽略并由 UTF-8 替代。 |
技术细节
返回值: | 返回被转换的字符串 |
PHP 版本: | 4.3.0+ |
更新日志:
版本 | 说明 |
---|---|
PHP 5 | character-set 参数的默认值改为 UTF-8。 |
PHP 5.4 |
新增了用于规定翻译表适用的文档类型的附加 flags:
|
PHP 5.3.4 | 다중 바이트编码 지원을 추가했습니다. |
더 많은 예제
예제 1
HTML 엔티티를 문자로 변환합니다:
<?php $str = "Bill & 'Steve'"; echo html_entity_decode($str, ENT_COMPAT); // 더블 쿼트만 변환 echo "<br>"; echo html_entity_decode($str, ENT_QUOTES); // 더블 쿼وت와 싱글 쿼트 변환 echo "<br>"; echo html_entity_decode($str, ENT_NOQUOTES); // 아무것도 변환하지 않음 ?>
위 코드의 HTML 출력 (원본 코드 보기):
<!DOCTYPE html> <html> <body> Bill & 'Steve'<br> Bill & 'Steve'<br> Bill & 'Steve' </body> </html>
위 코드의 브라우저 출력:
Bill & 'Steve' Bill & 'Steve' Bill & 'Steve'
예제 2
서유럽 문자 집합을 사용하여 HTML 엔티티를 문자로 변환합니다:
<?php $str = "My name is Øyvind Åsane. I'm Norwegian."; echo html_entity_decode($str, ENT_QUOTES, "ISO-8859-1"); ?>
위 코드의 HTML 출력 (원본 코드 보기):
<!DOCTYPE html> <html> <body> My name is ?yvind ?sane. I'm Norwegian. </body> </html>
위 코드의 브라우저 출력:
My name is ?yvind ?sane. I'm Norwegian.