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

WBOY
Release: 2016-06-06 20:50:24
Original
930 people have browsed it

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

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);
Copy after login
Copy after login

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

输出如下:

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

string(0)""

htmlspecialchars 的第三个参数是encoding

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

这样应该就没问题了

Related labels:
php
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template