php如何判断js或css文件的代码格式是gbk还是utf8(3)?
接问题2
http://topic.csdn.net/u/20100904/16/d4b423f4-0c29-4ef3-be17-7648085f6985.html我的代码:<?php
$localhost="../../";
$down_path=$localhost."down/";
$folder="gcshouji";//批量文件转码 gbk-utf8
function gbk_utf_fn($file_paths){
$files=glob($file_paths);
print_r($files);
foreach($files as $k=>$v){
$code=file_get_contents($v);
$lang=mb_detect_encoding($code,array("GB2312","UTF-8","ASCII","GBK"));
if(!($lang=="UTF-8")){
$code=iconv($lang,"UTF-8//IGNORE",$code);
$lang_r=mb_detect_encoding($code,array("GB2312","UTF-8","ASCII","GBK"));
echo $lang."===>".$lang_r."<br>";
file_put_contents($v,$code);
} }
}
function gbk_utf(){
global $down_path,$folder;
$js_path=$down_path.$folder."/js/";
$css_path=$down_path.$folder."/css/";
gbk_utf_fn($js_path."*.js");
gbk_utf_fn($css_path."*.css");
}gbk_utf();?>