Skip to content

Instantly share code, notes, and snippets.

@pascalchevrel
Created November 4, 2013 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pascalchevrel/7299680 to your computer and use it in GitHub Desktop.
Save pascalchevrel/7299680 to your computer and use it in GitHub Desktop.
This is a PHP function to check if a file has a UTF8 encoding, UTF8 files that only contain ASCII characters are detected as us-ascii by PHP.
<?php
function isUTF8($filename)
{
$info = finfo_open(FILEINFO_MIME_ENCODING);
$type = finfo_buffer($info, file_get_contents($filename));
finfo_close($info);
return ($type == 'utf-8' || $type == 'us-ascii') ? true : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment