添加“utf-8”出现 htmlspecialchars() 的参数 - 它会破坏任何东西吗?
假设我的项目始终是 utf-8 并且始终使用 utf-8 编码,如果我更改所有出现的 htmlspecialchars($var)
到 htmlspecialchars($var, ENT_QUOTES, 'utf-8')
?
我确实知道一件事:显然, ENT_QUOTES
与 ENT_COMPAT
不同,因为它也转义单引号。假设我知道仅此一个不会破坏任何东西,还有其他东西吗?
措辞不同:
在没有 charset 参数的情况下使用 htmlspecialchars() 时,仅从字符集中给出数据,是否有可能与 htmlspecialchars() 不同的结果何时与字符集参数一起使用?
(在任何时候,htmlspecialchars($stringThatIsValidUTF8, ENT_QUOTES) !== htmlspecialchars($stringThatIsValidUTF8, ENT_QUOTES, 'utf-8')
?)
我的理解是不,永远不会。 stackoverflow 上的另一个问题也建议不。到目前为止,浏览我的项目沙箱并进行了更改也表示“不”。但是,我不确定我是否忽略了某些事情。
Assuming my project is utf-8 throughout and has always been used with utf-8 encoding, is there anything legit that could possibly break if I change all occurrences of htmlspecialchars($var)
to htmlspecialchars($var, ENT_QUOTES, 'utf-8')
?
I do know one thing: Obviously, ENT_QUOTES
differs from ENT_COMPAT
in that it also escapes single quotation marks. Assuming I know that this alone won't break anything, is there anything else left over?
Differently worded:
Is there a conceivable result of htmlspecialchars() when used without the charset parameter, given data only from the charset, that would differ from htmlspecialchars() when used with the charset parameter?
(Is, at any point, htmlspecialchars($stringThatIsValidUTF8, ENT_QUOTES) !== htmlspecialchars($stringThatIsValidUTF8, ENT_QUOTES, 'utf-8')
?)
My understanding says no, never. Another question here on stackoverflow suggests no, too. So far, browsing my sandbox of the project with the changes also says no. However, I'm not sure if I'm overlooking something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为另一个问题中 PHP 手册中的引用明确地回答了这个问题:
"
&
>
等在每种编码中都具有相同的代码,甚至在 UTF-8 中它们也只需要一个字节,因为只有在必要时一个 UTF-8 字符才会占用多个字节,因此,即使您到目前为止一直使用 ISO-8859-1 处理 UTF-8 数据,当您切换到显式 UTF-8 时,输出也将是相同的。输入。I think the quote from the PHP manual in the other question answers it definitely:
"
&
>
and so on all have the same code in each of those encodings, and even in UTF-8 they require only one byte, because an UTF-8 character will occupy multiple bytes only when necessary. Therefore, even if you have been processing UTF-8 data with ISO-8859-1 until now, the output will be identical when you switch to explicit UTF-8 input.不,不会有什么不同,因为如果你没有提供任何字符集,PHP 会猜测它,因此它将使用 UTF-8。
No, it wouldn't differ, becouse if you didn't provide any charset, PHP will guess it, therefore it will use UTF-8.