-1

is UTF-8 not the same as ASCII? how you would explain the different results i get from:

$result = mb_detect_encoding($PLAINText, mb_detect_order(), true);

Sometimes i get "UTF-8" in $result and sometimes i get "ASCII". so they are different, but that is not my question, my question is why iconv() code doesn't convert from ASCII to UTF-8?

$result = iconv("ASCII","UTF-8//IGNORE",$PLAINText);

i check the $result encoding later using the mb_detect_encoding() function and it is still "ASCII" , not "UTF-8".

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
Rodniko
  • 4,926
  • 20
  • 69
  • 93
  • 1
    *"i know that UTF-8 is almost the same as ASCII"* - What? Hell, no. Recommended reading: http://www.joelonsoftware.com/articles/Unicode.html – Tomalak Apr 11 '13 at 07:15
  • Thanks, i edit the post so people won't be mistaken. so why the iconv() doesn't convert from ASCII to UTF-8? – Rodniko Apr 11 '13 at 07:56
  • 1
    It UTF-8 was the same as ASCII they'd call it ASCII. It just happens that the 127 characters of ASCII have the same byte value in UTF-8. Have you read the article I linked to? – Tomalak Apr 11 '13 at 08:09

1 Answers1

1

The reason is that when using only ASCII characters in an UTF-8 string, the UTF-8 string is indistinguishable from an ASCII string. (Unless a byte order mark is used, but it's optional.)

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173