当前位置:Gxlcms > PHP教程 > phphtmlentities汉字中文乱码问题解决办法_PHP教程

phphtmlentities汉字中文乱码问题解决办法_PHP教程

时间:2021-07-01 10:21:17 帮助过:3人阅读

本文章来给大家介绍php htmlentities汉字乱码问题解决办法,其实我们只要把接受数据转换成uft8即可解决汉字乱码了。

htmlentities函数作用在汉字变量中的时候会出现乱码

代码如下
$resultsText = str_replace("[QUERY]", htmlentities($query), $resultsText);

正确的做法是改变htmlentities的默认参数

htmlentities($query,ENT_COMPAT,'UTF-8')

代码如下

$query='你好';
$resultsText='1 条与 "[QUERY]" 相关的搜索结果';
$resultsText = str_replace("[QUERY]", htmlentities($query,ENT_COMPAT,'UTF-8'), $resultsText);
header('content-type: text/html; charset=utf-8');

print_r($resultsText);
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/633198.htmlTechArticle本文章来给大家介绍php htmlentities汉字乱码问题解决办法,其实我们只要把接受数据转换成uft8即可解决汉字乱码了。 htmlentities函数作用在汉字...

人气教程排行