ANSI编码文件使用php脚本转换为UTF-8编码文件?

Mar*_*eth 2 php linux converter utf-8 character-encoding

ANSI编码文件如何使用php或任何脚本或linux下的任何命令行转换为UTF-8编码文件?

Ohg*_*why 9

首先,ANSI不是一种字符编码.使用ANSI,您需要找出您尝试阅读的特定文件的编码选项.首先,如果文件已经是UTF-8编码,首先应该找出,如果没有,则只需编码.下面,我们检查编码,如果成功,我们返回文件.

$output = false;
if( !mb_check_encoding( $myFile, 'UTF-8', true ) ):
   $output = mb_convert_encoding( $myFile, 'UTF-8' ); 
endif;
Run Code Online (Sandbox Code Playgroud)

然后只需检查编码是否有效.

return $output ? $output : 'Failed encoding file!';
Run Code Online (Sandbox Code Playgroud)

  • @MarcellNemeth如果你可以使用命令行,那么我可能会使用`iconv`.`iconv -f iso-8859-1 -t utf-8 <infile> outfile`当然也会相应调整变量. (2认同)