0

I want to detect file encoding if it is ANSI or if it is UTF-8 and Unicode. I only find out how to Detect UTF-8

if (mb_detect_encoding(file_get_contents($file), 'UTF-8', true))
{
    echo "UTF-8";
}
NoNaMe
  • 6,020
  • 30
  • 82
  • 110
ImBigNoob
  • 1
  • 2
  • 4
  • 1
    There is no such thing as "ANSI text". You'll have to check for a specific legacy charset. Or "ASCII" if that is what you meant. – mario Sep 09 '15 at 09:54
  • 2
    And all you can really do is check if a file is not *valid* UTF-8. Other than that it's pretty much guesswork. – Phylogenesis Sep 09 '15 at 09:55
  • have a look at this link http://stackoverflow.com/questions/505562/detect-file-encoding-in-php – Niranjan N Raju Sep 09 '15 at 09:56
  • 4
    [The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)](http://www.joelonsoftware.com/articles/Unicode.html) – Phylogenesis Sep 09 '15 at 09:56

1 Answers1

0

/* Specify encoding_list character encoding by comma separated list */

echo mb_detect_encoding($str, "ASCII, UTF-8, UNICODE");

it will print the detected encoding with respect to list

Rohan Khude
  • 4,455
  • 5
  • 49
  • 47