日期:2014-05-17 浏览次数:20498 次
<?php // set_time_limit(0); $form = 'F:\work\sinykk\templates'; $to = 'F:\work\sinykk\templates'; //mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding ] ); copyDir($form, $to); function copyDir($dirSrc, $dirTo,$bianma='gb2312-gbk',$extlist=array('txt','js','php','inc','html','htm','css')) { if(!file_exists($dirTo)) { mkdir($dirTo); } if($dir_handle=@opendir($dirSrc)) { while($filename=readdir($dir_handle)) { if($filename!="." && $filename!="..") { $subSrcFile=$dirSrc."/".$filename; $subToFile=$dirTo."/".$filename; if(is_dir($subSrcFile)) { copyDir($subSrcFile, $subToFile); } if(is_file($subSrcFile)) { $ext = extname($subSrcFile); if(in_array($ext,$extlist)){ $r = file_get_contents($subSrcFile); $r = F_iconv($r,$bianma); file_put_contents($subToFile,$r); }else{ copy($subSrcFile, $subToFile); } } } } closedir($dir_handle); } } function F_iconv($P_strig,$P_types){ switch(strtolower($P_types)){ case 'gb2312-utf8' :{ $P_strig = iconv("GB2312","UTF-8",$P_strig); break; } case 'gb2312-gbk' :{ $P_strig = iconv("GB2312","GBK//ignore",$P_strig); break; } case 'gb2312-utf8-i' :{ $P_strig = iconv("GB2312","UTF-8//IGNORE",$P_strig); break; } case 'gb2312-utf8-t' :{ $P_strig = iconv("GB2312","UTF-8//TRANSLIT",$P_strig); break; } case 'utf8-gb2312' :{ $P_strig = iconv("UTF-8","GB2312",$P_strig); break; } case 'utf8-gb2312-i' :{ $P_strig = iconv("UTF-8","GB2312//IGNORE",$P_strig); break; } case 'utf8-gb2312-t' :{ $P_strig = iconv("UTF-8","GB2312//TRANSLIT",$P_strig); break; } } return $P_strig; } function extname($filename) { $pathinfo=pathinfo($filename); return strtolower($pathinfo['extension']); }