anon
anon

Reputation:

let htmlspecialchars use UTF-8 as default charset?

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)

Upvotes: 1

Views: 1985

Answers (2)

bobince
bobince

Reputation: 536379

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

Upvotes: 2

Pekka
Pekka

Reputation: 449415

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.

Upvotes: 1

Related Questions