PHP用fwrite写入文件中文乱码怎么办?

2020-08-13 10:42:16

PHP用fwrite写入文件中文乱码的解决办法:1、用【mb_detect_encoding()】函数获取内容编码方式;2、用【mb_convert_encoding()】函数将内容编码方式转换为【UTF-8】即可。

PHP用fwrite写入文件中文乱码的解决办法:

PHP用fwrite或file_put_contents写入文件内容中文乱码,许多人说PHP脚本编码方式是UTF-8,创建的文件就是UTF-8,然而事实不是这样。

解决方法很简单:

fwrite($fp, mb_convert_encoding( $content, 'UTF-8', mb_detect_encoding($content) ) );

mb_detect_encoding()函数获取内容编码方式,用mb_convert_encoding()函数将内容编码方式转换为UTF-8。

相关文章 大家在看