让htmlspecialchars使用UTF-8作为默认字符集? [英] let htmlspecialchars use UTF-8 as default charset?

查看:415
本文介绍了让htmlspecialchars使用UTF-8作为默认字符集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法告诉PHP使用UTF-8作为默认的函数 htmlspecialchars

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

我已经设置了:

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

如果没有,请发布一个所有函数的列表, $ c> charset ?

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

(我需要这个,因为我重新分解我的框架以使用UTF- p>

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

推荐答案

只需使用 htmlspecialchars()而不是 htmlentities ()。因为它不接触非ASCII字符,无论是否使用'utf8'字符集或默认'latin1'(*),结果是一样的。作为奖励,你的输出更小。 (

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.)

(*:有几个东亚多字节字符集可以不同的ASCII码点的使用,所以如果你使用那些你仍然需要传递 $ charset 参数到 htmlspecialchars()。但是对于UTF-8肯定没有这样的问题。)

(*: 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.)

这篇关于让htmlspecialchars使用UTF-8作为默认字符集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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