html_entity_decode() 函数把 HTML 实体转换为字符。
html_entity_decode() 是 htmlentities() 的反函数。
当把html代码显示在屏幕上,需要使用htmlentities()函数
有的时候我们需要反过来,则需要使用函数html_entity_decode(),将翻转的代码,重新翻译回来!
下面是一个例子:
例子
<?php $str = "John & 'Adams'"; 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 & 'Adams'<br /> John & 'Adams'<br /> John & 'Adams' </body> </html>