Detecting the right character encoding in PHP? -


i'm trying detect character encoding of string can't right result.
example:

$str = "€ ‚ ƒ „ …" ; $str = mb_convert_encoding($str, 'windows-1252' ,'html-entities') ; // $str should windows-1252-encoded string. // let's detect encoding: echo mb_detect_encoding($str,'windows-1252, iso-8859-1, utf-8') ; 

that code outputs iso-8859-1 should windows-1252.

what's wrong this?

edit:
updated example, in response @raina77ow.

$str = "€‚ƒ„…" ; // no white-spaces $str = mb_convert_encoding($str, 'windows-1252' ,'html-entities') ; $str = "hello $str" ; // let's add ascii characters echo mb_detect_encoding($str,'windows-1252, iso-8859-1, utf-8') ; 

i wrong result again.

the problem windows-1252 in php never detected, because text contains characters outside of 0x80 0x9f, not detected windows-1252.

this means if string contains normal ascii letter "a", or space character, php not valid windows-1252 and, in case, fall next possible encoding, iso 8859-1. php bug, see https://bugs.php.net/bug.php?id=64667.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -