Frage

How can ANSI encoded file converting to UTF-8 encoded file with php, or any script, or any command line under linux?

War es hilfreich?

Lösung

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!';

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top