Created
November 4, 2013 08:26
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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