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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:50:24
Original
1005 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
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template