首页 > php函数 > php html_entity_decode实例教程

php html_entity_decode实例教程

关于html_entity_decode在大多数情况下是与htmlspecialchars htmlentities配合使用的

html_entity_decode用法:
string html_entity_decode ( string $string [, int $quote_style = ENT_COMPAT [, string $charset ]] )

html_entity_decode() 函数把 HTML 实体转换为字符。

html_entity_decode() 是 htmlentities() 的反函数也html_entity_decode() 是 htmlspecialchars() 的反函数。

 

$str = "A 'quote' is <b>bold http://www.phprm.com>";

Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
$s = htmlspecialchars($str);

echo $s;

Outputs: A &#039;quote&#039; is &lt;b&gt;boldwww.phprm.com&lt;/b&gt;

echo html_entity_decode($s);

A 'quote' is bold

再看一个实例

<?php
$str = "John &amp; &#039;Adams&#039;";
echo html_entity_decode($str);
echo "<br />";
echo html_entity_decode($str, ENT_QUOTES);
echo "<br />";
echo html_entity_decode($str, ENT_NOQUOTES);
?>浏览器输出:

John & 'Adams'
John & 'Adams'
John & 'Adams'如果在浏览器中查看源代码,会看到这些 HTML:

<html>
<body>
John & &#039;Adams&#039;<br />
John & 'Adams'<br />
John & &#039;Adams&#039;
</body>
</html>



本文地址:http://www.phprm.com/function/84074895dffabc89f50e3e0d0e2dd66b.html

转载随意,但请附上文章地址:-)

标签:none

发表留言