Skip to content

Instantly share code, notes, and snippets.

@feng-ming
Last active December 13, 2015 20:28
Show Gist options
  • Save feng-ming/4970006 to your computer and use it in GitHub Desktop.
Save feng-ming/4970006 to your computer and use it in GitHub Desktop.
检测文件是否是UTF-8编码。 转换非UTF-8编码的文件到UTF-8编码
<?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