如何使用 php 将汉字转换成 html 实体
想要将汉字转换为 html 实体,也就是将浏览器上显示为普通文本,但查看源代码时显示为一系列数字的格式,我们可以使用 php 中的 html 实体转换函数。
解决方法
要将汉字转换成 html 实体,可以使用 php 的 mb_convert_encoding 函数,它可以将给定的文本从一种编码转换为另一种编码。对于此案例,我们将使用 'html-entities' 编码来进行转换。
代码示例
echo mb_convert_encoding ('大家好哈', 'html-entities');
输出
你好请一身
解释