PHP html_entity_decode() 함수
예시
HTML 엔티티를 문자로 변환:
<?php
$str = '<a href="https://www.w3schools.com">w3schools.com</a>';
echo html_entity_decode($str);
?>
위 코드의 HTML 출력은 (소스 보기):
<a href="https://www.w3schools.com">w3schools.com</a>
위 코드의 브라우저 출력은 다음과 같습니다.
정의 및 사용
html_entity_decode() 함수는 HTML 엔티티를 문자로 변환합니다.
html_entity_decode() 함수는 htmlentities() 의 반대입니다 .
통사론
html_entity_decode(string,flags,character-set)
매개변수 값
Parameter | Description |
---|---|
string | Required. Specifies the string to decode |
flags | Optional. Specifies how to handle quotes and which document type to use. The available quote styles are:
Additional flags for specifying the used doctype:
|
character-set | Optional. A string that specifies which character-set to use. Allowed values are:
Note: Unrecognized character-sets will be ignored and replaced by ISO-8859-1 in versions prior to PHP 5.4. As of PHP 5.4, it will be ignored an replaced by UTF-8. |
기술적 세부 사항
반환 값: | 변환된 문자열을 반환 |
---|---|
PHP 버전: | 4.3.0+ |
변경 로그: | PHP 5.6 - 문자 집합
매개변수의 기본값을 기본 문자 집합의 값으로 변경했습니다(구성에서). PHP 5.4 - 문자 집합 매개변수 의 기본값 을 UTF-8로 변경했습니다. PHP 5.4 - ENT_HTML401, ENT_HTML5, ENT_XML1 및 ENT_XHTML이 추가되었습니다. PHP 5.0 - 멀티바이트 인코딩 지원 추가 |
더 많은 예
예시
일부 HTML 엔티티를 문자로 변환:
<?php
$str = "Albert Einstein said: 'E=MC²'";
echo
html_entity_decode($str, ENT_COMPAT); // Will only convert double quotes
echo "<br>";
echo html_entity_decode($str, ENT_QUOTES); // Converts double
and single quotes
echo "<br>";
echo html_entity_decode($str, ENT_NOQUOTES); // Does not
convert any quotes
?>
위 코드의 HTML 출력은 (소스 보기):
Albert Einstein said: 'E=MC²'<br>
Albert Einstein said: 'E=MC²'<br>
Albert Einstein said: 'E=MC²'
위 코드의 브라우저 출력은 다음과 같습니다.
Albert Einstein said: 'E=MC²'
Albert Einstein said: 'E=MC²'
Albert
Einstein said: 'E=MC²'
예시
서유럽 문자 집합을 사용하여 일부 HTML 엔터티를 문자로 변환합니다.
<?php
$str = "My name is Øyvind Åsane. I'm Norwegian.";
echo html_entity_decode($str, ENT_QUOTES, "UTF-8");
?>
위 코드의 HTML 출력은 (소스 보기):
My name is Øyvind Åsane. I'm Norwegian.
위 코드의 브라우저 출력은 다음과 같습니다.
My name is Øyvind Åsane. I'm Norwegian.
❮ PHP 문자열 참조