I am trying to detect character encoding of a string, but I cannot get the correct result.
For instance:
$str = "€ ‚ ƒ „ …" ; $str = mb_convert_encoding($str, 'Windows-1252' ,'HTML-ENTITIES') ; // Now $str should be a Windows-1252-encoded string. // Let detect its encoding: echo mb_detect_encoding($str,'Windows-1252, ISO-8859-1, UTF-8') ;
This code outputs ISO-8859-1 , but it should be Windows-1252 .
What happened to this?
EDIT:
Updated example, in response to @ raina77ow.
$str = "€‚ƒ„…" ; // no white-spaces $str = mb_convert_encoding($str, 'Windows-1252' ,'HTML-ENTITIES') ; $str = "Hello $str" ; // let add some ascii characters echo mb_detect_encoding($str,'Windows-1252, ISO-8859-1, UTF-8') ;
I get the wrong result again.
source share