This article will introduce to you the solution to the problem of garbled Chinese characters in php htmlentities. In fact, we only need to convert the received data into uft8 to solve the problem of garbled Chinese characters.
When the htmlentities function is used in Chinese character variables, garbled characters will appear
代码如下 |
复制代码 |
$resultsText = str_replace("[QUERY]", htmlentities($query), $resultsText);
|
The correct approach is to change the default parameters of htmlentities
htmlentities($query,ENT_COMPAT,'UTF-8')
The code is as follows
代码如下 |
复制代码 |
$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);
?>
|
|
Copy code |
|
$query='Hello';
$resultsText='1 search results related to "[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.bkjia.com/PHPjc/633198.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/633198.htmlThis article will introduce to you the solution to the garbled Chinese character problem in php htmlentities. In fact, we only need to convert the received data into uft8. The garbled Chinese characters can be solved. The htmlentities function works on Chinese characters...
Statement: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