PHP의 htmlspecialchars_decode () 함수
예
미리 정의 된 HTML 엔티티 "& LT;"(이하) 및 "한다"(이상) 문자로 :
<?php
$str = "This is some <b>bold</b> text.";
echo htmlspecialchars_decode($str);
?>
$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>
<html>
<body>
This is some <b>bold</b> text.
</body>
</html>
다음과 같이 위의 코드의 브라우저 출력은 다음과 같습니다
This is some bold text.
정의 및 사용
문자 몇 가지 미리 정의 된 HTML 개체에 htmlspecialchars_decode () 함수.
복호화되는 HTML 엔티티은 다음과 같습니다 :
- & 앰프; &로 디코딩 (앰퍼샌드)
- & Quot은, "로 디코딩 (큰 따옴표)
- (작은 따옴표) '는로 디코딩'
- & 중위가, 디코딩 된 <(미만)
- 된다은, 디코딩> (보다 큼)
htmlspecialchars_decode () 함수는 ()은 htmlspecialchars 함수의 역함수.
문법
htmlspecialchars_decode( string,flags )
参数 | 描述 |
---|---|
string | 必需。规定要解码的字符串。 |
flags | 可选。规定如何处理引号以及使用哪种文档类型。 可用的引号类型:
规定使用的文档类型的附加 flags:
|
기술 세부 사항
반환 값 : | 변환 된 문자열을 반환합니다. |
---|---|
PHP 버전 : | 5.1.0+ |
업데이트 로그 : | ENT_HTML401, ENT_HTML5, ENT_XML1 및 ENT_XHTML : PHP 5.4에서 문서 유형에 대한 추가 플래그를 사용하여 요구 사항을 추가합니다. |
더 많은 예제
예 1
문자로 일부 미리 정의 된 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
?>
$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>
<html>
<body>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'
</body>
</html>
다음과 같이 위의 코드의 브라우저 출력은 다음과 같습니다
Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
예 2
큰 따옴표로 미리 정의 된 HTML 엔티티 :
<?php
$str = 'I love "PHP".';
echo htmlspecialchars_decode($str, ENT_QUOTES); // Converts double and single quotes
?>
$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>
<html>
<body>
I love "PHP".
</body>
</html>
다음과 같이 위의 코드의 브라우저 출력은 다음과 같습니다
I love "PHP".
PHP 문자열 참조