服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > php教程 >

PHP URL传递中文乱码问题解决办法

时间:2016-01-31 09:35来源: 作者: 点击:
php htmlentities汉字乱码问题解决办法,其实我们只要把接受数据转换成uft8即可解决汉字乱码了。 htmlentities函数作用在汉字变量中的时候会出现乱码 代码如下 $resultsText = str_replace([QUERY],
php htmlentities汉字乱码问题解决办法,其实我们只要把接受数据转换成uft8即可解决汉字乱码了。
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); 
?>

(责任编辑:最模板)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
热点内容