My framework for each pages does the follow:
ini_set('mbstring.internal_encoding','UTF-8');
ini_set('mbstring.func_overload',7);
header('Content-Type: text/html; charset=UTF-8');
Do I need to do a ini_set( 'default_charset', 'UTF-8' );
too?
PHP UTF-8 Encoding – modifications to your php. The first thing you need to do is to modify your php. ini file to use UTF-8 as the default character set: default_charset = "utf-8"; (Note: You can subsequently use phpinfo() to verify that this has been set properly.)
The utf8_encode() function is an inbuilt function in PHP which is used to encode an ISO-8859-1 string to UTF-8. Unicode has been developed to describe all possible characters of all languages and includes a lot of symbols with one unique number for each symbol/character.
Definition and Usage The utf8_encode() function encodes an ISO-8859-1 string to UTF-8. Unicode is a universal standard, and has been developed to describe all possible characters of all languages plus a lot of symbols with one unique number for each character/symbol.
No, you don't have to.
header('Content-Type: text/html; charset=UTF-8');
sets this for every page already
Please see https://bugs.php.net/bug.php?id=29983 looks to me like some distros still have the problem
test case
echo "ini_get('default_charset') ". ini_get('default_charset')."<br>";
if (!ini_set('default_charset', 'utf-8')) {
echo "could not set default_charset to utf-8<br>";
}
When it comes to the http-header, you're OK as the other answers explain.
But: There are some functions that are default charset aware
From the description of FILTER_SANITIZE_FULL_SPECIAL_CHARS:
Like htmlspecialchars, this filter is aware of the default_charset and if a sequence of bytes is detected that makes up an invalid character in the current character set then the entire string is rejected resulting in a 0-length string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With