PHP-htmlspecialchars和UTF-8 [英] PHP - htmlspecialchars and UTF-8

查看:65
本文介绍了PHP-htmlspecialchars和UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是尝试使用 htmlspecialchars 进行确认.我刚刚将数据库转换为UTF-8,我想我终于可以正常使用了,但是在我的代码中,我一直使用 PHP 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);

PHP文档表明我不需要,但这是真的吗?

The PHP documention suggests I don't need to, but is that true?

就此功能而言,字符集ISO-8859-1,ISO-8859-15,UTF-8,cp866,cp1251,cp1252和KOI8-R实际上等效,因为这些字符受htmlspecialchars()在所有这些字符集中占据相同的位置.

推荐答案

由htmlspecialchars()处理"的所有字符都位于7位/美国

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.

这篇关于PHP-htmlspecialchars和UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆