<?php
function change_code($filename,$output_encoding){
if(file_exists($filename)){
if(is_dir($filename)){
foreach (glob("$filename/*") as $key=>$value){
change_code($value,$output_encoding);
}
}else{
$contents_before = file_get_contents($filename);;
$code = mb_detect_encoding($contents_before, array('ASCII','GB2312','GBK','UTF-8'));
$contents_after = iconv($code,$output_encoding,$contents_before);
file_put_contents($filename, $contents_after);
}
}else{
echo '参数错误';
return false;
}
}
change_code('./test','utf-8');
echo "success!";
?>