Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php空字符串htmlspecialchars()_Php_String_Htmlspecialchars - Fatal编程技术网

php空字符串htmlspecialchars()

php空字符串htmlspecialchars(),php,string,htmlspecialchars,Php,String,Htmlspecialchars,因此,我试图使用htmlspecialchars()来保护我的网站,但不幸的是,我陷入了这段代码中: <?php function wrap_nome($firstname, $lastname) { $join = htmlspecialchars($firstname, ENT_QUOTES) . ' ' . htmlspecialchars($lastname, ENT_QUOTES); if (mb_strlen($join) > 32) { $text = substr(

因此,我试图使用
htmlspecialchars()
来保护我的网站,但不幸的是,我陷入了这段代码中:

<?php

function wrap_nome($firstname, $lastname)
{
$join = htmlspecialchars($firstname, ENT_QUOTES) . ' ' . htmlspecialchars($lastname, ENT_QUOTES);
if (mb_strlen($join) > 32)
{
$text = substr($join,0,32);
return $text . " ...";
}
else
{
return $join;
}
}

$nome = wrap_nome($firstname, $lastname);

echo '<span style="color:#7F7F7F;font-family:Arial;font-size:13px;"><b>' . $nome . '</b></span>';

?>
。。。它不会输出任何东西

你知道是什么原因吗?

只需更换

htmlspecialchars($str,entu QUOTES)


htmlentities($st,ENT_引号,“UTF-8”)

htmlspecialchars
如果出现错误,则返回
FALSE
,如果
$nome
包含任何无法在指定字符集中表示的字符,则会发生这种情况。PHP5.4之前的字符集默认为
ISO8859-1
UTF-8
,此后,请尝试使用
htmlspecialchars($nome,entu QUOTES,'ISO8859-1')


如果这不起作用,请参阅中的字符集列表,并为您的姓名使用相应的字符集。

如果一个函数不起作用,为什么一个函数要起作用?他们不一样!重要的不是函数,而是
UTF-8
参数。我知道,但这应该在答案中。所以我对添加第三个参数字符集投了反对票(名称是什么语言?葡萄牙语来自葡萄牙$nome=“F.A.b.i.o..H.e.n.r.r.i.q.u.e.”从数据库中可以看出数据库使用的是什么编码?你说对了,问题出在哪里caracter!!!我刚删除了它,它就成功了。我只需要找到正确的字符集。是的,如果我删除了htmlspecialchars(),这两个变量在页面中的任何位置都能很好地回显。一切正常
echo '<span style="color:#7F7F7F;font-family:Arial;font-size:13px;"><b>' . htmlspecialchars($nome, ENT_QUOTES) . '</b></span>';