Created
June 20, 2014 17:44
-
-
Save categulario/c986dc051a8a44ce3afa to your computer and use it in GitHub Desktop.
php change file encoding
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
| <?php | |
| $filename = "changeme.csv"; | |
| $handle = fopen($filename, "r"); | |
| $contents = fread($handle, filesize($filename)); | |
| fclose($handle); | |
| if (!mb_check_encoding($contents, 'UTF-8') | |
| OR !($contents === mb_convert_encoding(mb_convert_encoding($contents, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) { | |
| $contents = mb_convert_encoding($contents, 'UTF-8'); | |
| } | |
| $fp = fopen('changed.csv', 'w'); | |
| fwrite($fp, $contents);; | |
| fclose($fp); | |
| echo 'done!'.PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment