Home  >  Article  >  Backend Development  >  PHP中 htmlspecialchars 函数传入中文变量值后返回空字符串

PHP中 htmlspecialchars 函数传入中文变量值后返回空字符串

WBOY
WBOYOriginal
2016-06-06 20:50:24885browse

$a = $_GET['t'];
var_dump($a);
echo "then.......<hr>";
$b = htmlspecialchars($a);
var_dump($b);

http://localhost/test.php?t=中文字符

输出如下:

string(8)"中文字符"then.......

string(0)""

回复内容:

$a = $_GET['t'];
var_dump($a);
echo "then.......<hr>";
$b = htmlspecialchars($a);
var_dump($b);

http://localhost/test.php?t=中文字符

输出如下:

string(8)"中文字符"then.......

string(0)""

htmlspecialchars 的第三个参数是encoding

<code>$b = htmlspecialchars($a,ENT_QUOTES,'UTF-8');
</code>

这样应该就没问题了

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