Created
November 27, 2012 11:09
-
-
Save mikkohei13/4153678 to your computer and use it in GitHub Desktop.
Checks if file is UTF-8 and without BOM
This file contains hidden or 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
/* | |
Thanks to | |
http://www.php.net/manual/en/function.mb-detect-encoding.php#91051 | |
http://stackoverflow.com/questions/8907196/check-if-csv-file-is-in-utf-8-with-php | |
*/ | |
if (! mb_check_encoding($data, 'UTF-8')) { | |
exit("Not UTF-8"); | |
} | |
else | |
{ | |
define ('UTF8_BOM' , chr(0xEF) . chr(0xBB) . chr(0xBF)); | |
$first3 = substr($data, 0, 3); | |
if ($first3 == UTF8_BOM) | |
{ | |
exit("UTF-8 with BOM"); | |
} | |
else | |
{ | |
exit("UTF-8 without BOM"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi, i want save the file without bom how can i do?