开发者

let htmlspecialchars use UTF-8 as default charset?

开发者 https://www.devze.com 2023-03-09 14:54 出处:网络
Is there a way to tell PHP to use UTF-8 as default for functions like htmlspecialcha开发者_JAVA百科rs ?

Is there a way to tell PHP to use UTF-8 as default for functions like htmlspecialcha开发者_JAVA百科rs ?

I have already setted this:

ini_set('mbstring.internal_encoding','UTF-8');
ini_set('mbstring.func_overload',7);

If not, please can you post a list of all functions where I need to specify the charset?

(I need this because I am re-factorizing all my framework to get working with UTF-8)


Just use htmlspecialchars() instead of htmlentities(). Because it doesn't touch the non-ASCII characters, it doesn't matter whether you use 'utf8' charset or the default 'latin1'(*), the results are the same. As a bonus your output is smaller. (Though it does mean you have to ensure you're actually serving your page with the correct encoding.)

(*: there are a few East Asian multibyte charsets which can differ in their use of ASCII code points, so if you're using those you would still need to pass a $charset argument to htmlspecialchars(). But certainly no such problem for UTF-8.)


Is there a way to tell PHP to use UTF-8 as default for functions like htmlspecialchars ?

Nope, not as far as I know. mbstring.internal_encoding will define a default encoding for the mb_* family of functions only.

If not, please can you post a list of all functions where I need to specify the charset?

I'm not sure whether such a list exists - if in doubt, just walk through the manual and look out for any charset parameters.

0

精彩评论

暂无评论...
验证码 换一张
取 消