首页 > php开发 > php htmlentities汉字中文乱码问题解决办法

php htmlentities汉字中文乱码问题解决办法

htmlentities函数作用在汉字变量中的时候会出现乱码,代码如下:$resultsText = str_replace("[QUERY]", htmlentities($query), $resultsText);

正确的做法是改变htmlentities的默认参数:htmlentities($query,ENT_COMPAT,'UTF-8'),代码如下:

<?php  
$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);

               
               

文章网址:http://www.phprm.com/develop/fs818.html

随意转载^^但请附上教程地址。

标签:中文乱码 汉字 htmlentities

相关文章

发表留言