PHP - htmlspecialchars and UTF-8

自古美人都是妖i 提交于 2019-12-24 03:35:24

问题


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:


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.



来源:https://stackoverflow.com/questions/1839203/php-htmlspecialchars-and-utf-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!