PHP htmlspecialchars_decode() 함수
예시
미리 정의된 HTML 엔터티 "<"를 변환합니다. (보다 작음) 및 ">" (보다 큼) 문자:
<?php
$str = "This is some <b>bold</b> text.";
echo htmlspecialchars_decode($str);
?>
위 코드의 HTML 출력은 (소스 보기):
<!DOCTYPE html>
<html>
<body>
This is some <b>bold</b> text.
</body>
</html>
위 코드의 브라우저 출력은 다음과 같습니다.
This is some bold text.
정의 및 사용
htmlspecialchars_decode() 함수는 미리 정의된 일부 HTML 엔터티를 문자로 변환합니다.
디코딩될 HTML 엔터티는 다음과 같습니다.
- & &(앰퍼샌드)가 됩니다.
- " "(큰따옴표)가 됩니다.
- ' '(작은따옴표)가 됩니다.
- < <(보다 작음)이 됩니다.
- > >(보다 큼)
htmlspecialchars_decode() 함수는 htmlspecialchars() 의 반대 입니다 .
통사론
htmlspecialchars_decode(string,flags)
매개변수 값
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:
|
기술적 세부 사항
반환 값: | 변환된 문자열을 반환 |
---|---|
PHP 버전: | 5.1.0+ |
변경 로그: | PHP 5.4 - ENT_HTML401, ENT_HTML5, ENT_XML1 및 ENT_XHTML이 추가되었습니다. |
더 많은 예
예시
일부 미리 정의된 HTML 엔터티를 문자로 변환합니다.
<?php
$str = "Jane & 'Tarzan'";
echo htmlspecialchars_decode($str, ENT_COMPAT); // Will only convert double quotes
echo "<br>";
echo htmlspecialchars_decode($str, ENT_QUOTES); // Converts double and single quotes
echo "<br>";
echo htmlspecialchars_decode($str, ENT_NOQUOTES); // Does not convert any quotes
?>
위 코드의 HTML 출력은 (소스 보기):
<!DOCTYPE html>
<html>
<body>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'
</body>
</html>
위 코드의 브라우저 출력은 다음과 같습니다.
Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
예시
미리 정의된 HTML 엔터티를 큰따옴표로 변환합니다.
<?php
$str = 'I love "PHP".';
echo htmlspecialchars_decode($str, ENT_QUOTES); // Converts double and single quotes
?>
위 코드의 HTML 출력은 (소스 보기):
<!DOCTYPE html>
<html>
<body>
I love "PHP".
</body>
</html>
위 코드의 브라우저 출력은 다음과 같습니다.
I love "PHP".
❮ PHP 문자열 참조