Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.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和htmlspecialchars拒绝处理字符串_Php_Mysql_Row_Html Entities_Htmlspecialchars - Fatal编程技术网

Php htmlspecialchars和htmlspecialchars拒绝处理字符串

Php htmlspecialchars和htmlspecialchars拒绝处理字符串,php,mysql,row,html-entities,htmlspecialchars,Php,Mysql,Row,Html Entities,Htmlspecialchars,自从上次在我的Debian框中更新到PHP5.4.0-3以来,我注意到一些页面上有空字段,MySQL数据库中的文本应该在这些字段中显示 我玩了一会儿,发现了问题 奇怪的是,这是印刷品: string(18)“PHPHPHU3:论坛” 字符串(0)” 字符串(18)“php hu2分数规则” 字符串(0)” 字符串(6)“php hu” 字符串(0)” 字符串(15)“HU 8:Binarycnt” 字符串(0)” 但是如果我使用htmlentities和硬编码内容->htmlentitie

自从上次在我的Debian框中更新到PHP5.4.0-3以来,我注意到一些页面上有空字段,MySQL数据库中的文本应该在这些字段中显示

我玩了一会儿,发现了问题


奇怪的是,这是印刷品:

string(18)“PHPHPHU3:论坛”
字符串(0)”
字符串(18)“php hu2分数规则”
字符串(0)”
字符串(6)“php hu”
字符串(0)”
字符串(15)“HU 8:Binarycnt”
字符串(0)”
但是如果我使用htmlentities和硬编码内容->htmlentities(“测试”);它很有魅力。 如果我这样做:

var_dump(“a”。$scrow['name']);
它还说

字符串(0)”
但它变得更奇怪了。如果我将htmlspecialchars或HtmlSpecialTies与数据库中的任何其他变量一起使用,它就可以完美地工作

var_dump(htmlspecialchars($scrow['ID']);//打印例如字符串(2)“87”

这是什么原因造成的?

试试这个:

htmlentities($scrow['name'], ENT_QUOTES | ENT_IGNORE, "UTF-8");

原因可能是数据库返回的另一种编码(如UTF8)

因此,请使用
utf8\u编码($string)
utf8\u解码($string)

另一种方法是使用htmlentities的编码参数:


推荐的方法是每次使用htmlentities时对字符集进行硬编码

这是htmlentities调用的一个特性,不受默认字符集的影响。

这似乎有效。。但是它杀死了我的灵魂。。为什么这在更新之前没有问题?@Christian如果你使用
ISO-8859-1
cp1252
,而不是
UTF-8
,那会怎么样呢!谢谢有没有办法告诉php应该始终使用ISO-8859-1,而不必在每次htmlentities调用中都添加ISO-8859-1?奇怪的是,它一天前就工作了。没有更改代码也没有更改数据库