Is there a way to tell PHP to use UTF-8 as default for functions like htmlspecialchars
?
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 ofhtmlentities()
. 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 tohtmlspecialchars()
. But certainly no such problem for UTF-8.)Nope, not as far as I know.
mbstring.internal_encoding
will define a default encoding for the mb_* family of functions only.I'm not sure whether such a list exists - if in doubt, just walk through the manual and look out for any
charset
parameters.