Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-05-25 16:51:53
Original
1762 people have browsed it

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

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

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

print_r($resultsText);
Copy after login

               
               

文章网址:

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template