5

According to bin2hex my PHP is internally using UTF-8:

echo bin2hex("ö"); -> c3b6 (utf-8) echo bin2hex(utf8_decode("ö")); -> f6 (ISO-8859) 

But both mb_internal_encoding() and iconv_get_encoding() say it is ISO-8859-1.

echo mb_internal_encoding(); -> ISO-8859-1 var_dump(iconv_get_encoding()); -> ["input_encoding"]=> string(10) "ISO-8859-1" ["output_encoding"]=> string(10) "ISO-8859-1" ["internal_encoding"]=> string(10) "ISO-8859-1" 

UTF-8 seems to apparently be the one it's using, but why is it showing ISO-8859-1 anyway?

2

2 Answers 2

7

This is not strange at all. Your first check is for what is between the quotes. I assume you have saved the file using UTF-8 which means you have two bytes in your string. This does not imply that the internal encoding is UTF-8, just that you have those two bytes in you string.

Sign up to request clarification or add additional context in comments.

5 Comments

Oh, right. For what is the internal encoding getting used at all?
You shouldn't rely on it, always explicitly state the encoding.
@Sven What's the best method of doing so?
All mb_string functions have a parameter to specify the encoding used. The same applies to iconv. Never rely on an internal setting to be right, always explicitply pass "UTF-8" as encoding.
If I am using UTF-8 in PHP, I must always use the mb_ safe functions, right?
4

This is a default setting in php.ini :

[iconv] ;iconv.input_encoding = ISO-8859-1 ;iconv.internal_encoding = ISO-8859-1 ;iconv.output_encoding = ISO-8859-1 

If you want to use UTF-8 everywhere you should use these settings :

default_charset = "UTF-8" [iconv] iconv.input_encoding = UTF-8 iconv.internal_encoding = UTF-8 iconv.output_encoding = UTF-8 [mbstring] mbstring.language = Neutral mbstring.internal_encoding = UTF-8 mbstring.http_input = auto mbstring.http_output = UTF-8 mbstring.encoding_translation = On mbstring.detect_order = auto mbstring.substitute_character = none; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.