ANSI encoded file converting to UTF-8 encoded file with php script?
13,511
Solution 1
Firstly, ANSI is not a type of character encoding. With ANSI, you need to find out what the encoding options are for the particular file that you're trying to read. First you should find out first if the file is already UTF-8 encoded, and if not, then simply encode it. Below, we check the encoding and if successful we return the file.
$output = false;
if( !mb_check_encoding( $myFile, 'UTF-8', true ) ):
$output = mb_convert_encoding( $myFile, 'UTF-8' );
endif;
Then simply check if the encoding worked.
return $output ? $output : 'Failed encoding file!';
Solution 2
Not my answer but highlighting one of the comments on Ohgodwhy's answer:
If you can use the command line then I would probably use iconv for this.
iconv -f iso-8859-1 -t utf-8 <infile >outfile
and of course adjust the variables accordingly. – Ohgodwhy
Author by
Marcell Nemeth
Updated on June 05, 2022Comments
-
Marcell Nemeth about 2 years
How can ANSI encoded file converting to UTF-8 encoded file with php, or any script, or any command line under linux?