Last active
December 13, 2015 20:28
-
-
Save feng-ming/4970006 to your computer and use it in GitHub Desktop.
检测文件是否是UTF-8编码。
转换非UTF-8编码的文件到UTF-8编码
This file contains 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 | |
//检测字符串是否是utf-8编码 | |
if(mb_detect_encoding($content,"UTF-8, ISO-8859-1, GBK, gb2312") !== 'UTF-8') | |
{ | |
$content = iconv("gbk","utf-8",$content); | |
} | |
//转换文件为utf-8编码的文件,如果该文件开始即为utf-8,则不会做任何处理 | |
enca -L zh_CN -x UTF-8 $script_dir/../upload/text/$1.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment