我只是想用 htmlspecialchars 确认一些内容。我刚刚将数据库转换为 UTF-8,我想我终于可以正常工作了,但在我的代码中,我使用了 PHP htmlspecialchars
函数:
htmlspecialchars($val, ENT_QUOTES,'ISO-8859-1',false);
我是否需要担心将所有条目更改为:
htmlspecialchars($val, ENT_QUOTES,'UTF-8',false);
PHP 文档建议我不需要,但这是真的吗?
就该函数而言,字符集 ISO-8859-1、ISO-8859-15、UTF-8、cp866、cp1251、cp1252 和 KOI8-R 实际上是等效的,因为受htmlspecialchars() 在所有这些字符集中占据相同的位置。
I am just trying to confirm something with htmlspecialchars. I have just converted my database into UTF-8, and I think I finally have it all working, but throughout my code I have used the PHP htmlspecialchars
function:
htmlspecialchars($val, ENT_QUOTES,'ISO-8859-1',false);
Do I need to worry about changing all the entries to:
htmlspecialchars($val, ENT_QUOTES,'UTF-8',false);
The PHP documention suggests I don't need to, but is that true?
For the purposes of this function, the charsets ISO-8859-1, ISO-8859-15, UTF-8, cp866, cp1251, cp1252, and KOI8-R are effectively equivalent, as the characters affected by htmlspecialchars() occupy the same positions in all of these charsets.
发布评论
评论(1)
htmlspecialchars()“处理”的所有字符都在 7 位/US ASCII 范围内。这些在所提到的编码中是相同的(并且不会弄错)。所以是的,如果你不改变编码参数,不会有什么坏处。但无论如何我还是鼓励你这样做。
All characters "handled" by htmlspecialchars() are in the 7-bit/US ASCII range. And those are identical (and unmistakable) in the mentioned encodings. So yes, it will do no harm if you don't change the encoding parameter. But I'd encourage you to do so anyway.