//1.遍历出所有html文件
$dir = './jquery/jquery/'; //文件目录、
$move_to = './jquery/jquery_new/';
foreach(glob($dir . '*.htm*') as $html)
{
//读取文件
$fp = fopen($html, 'a+');
$html_string = fread($fp, filesize($html));
//转码操作
$html_string = str_replace('charset=gb2312', 'charset=UTF-8', $html_string);
$file_code = mb_detect_encoding()($html_string, array('UTF-8','GBK','LATIN1','BIG5'));
if($file_code = 'CP936')
{
$html_string = mb_convert_encoding($html_string ,'utf-8' , 'gbk');
}
//获取文件名
$slice = explode('/', $html);
$file_name = end($slice);
//移到新文件
file_put_contents($move_to . $file_name, $html_string);
fclose($fp);
}
echo 'ok, 执行完成';
|