其实小编在发表这篇文章之前对htmlentities() 和html_entity_decode()函数也没有过多的研究,每次使用到这两个函数时就去查看手册,但今天小编对这两个函数仔细研究了一下,给大家分享一下我对这两个函数的理解。

 

htmlentities() 和html_entity_decode()是一对逆函数,htmlentities负责将html字符转换为HTML实体,而html_entity_decode负责将HTML实体转化为html字符:

<?php
$str=\"what\'s this\";
$en_str=htmlentities($str,ENT_QUOTES);
echo $en_str.\"<br/>\";

echo html_entity_decode($en_str,ENT_QUOTES);

?>

运行后浏览器输出如下:

what\'s this
what\'s this

查看页面源码,结果如下:

what&#039;s this<br/>what\'s this

可以看出html_entity_decode函数将被htmlentities处理过的字符串还原了。

收藏 打印