添加“utf-8”出现 htmlspecialchars() 的参数 - 它会破坏任何东西吗?

发布于 2024-08-17 06:51:03 字数 808 浏览 2 评论 0原文

假设我的项目始终是 utf-8 并且始终使用 utf-8 编码,如果我更改所有出现的 htmlspecialchars($var)htmlspecialchars($var, ENT_QUOTES, 'utf-8')

我确实知道一件事:显然, ENT_QUOTESENT_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

宣告ˉ结束 2024-08-24 06:51:03

我认为另一个问题中 PHP 手册中的引用明确地回答了这个问题:

就该函数而言,字符集 ISO-8859-1、ISO-8859-15、UTF-8、cp866、cp1251、cp1252 和 KOI8-R 实际上是等效的,因为受 htmlspecialchars() 影响的字符在所有这些字符集中占据相同的位置。

" & > 等在每种编码中都具有相同的代码,甚至在 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:

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.

" & > 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.

贵在坚持 2024-08-24 06:51:03

不,不会有什么不同,因为如果你没有提供任何字符集,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文