用php做Big5轉Utf8 的檔案
發表於 : 2007-06-27 14:56:03
<?
//參數設定
$changelog = "utf8.log";
$dir_do = "source";
$dir_utf8 = "/var/www/html/target/";
//讀取上次轉換時間
$fp1 = fopen($changelog,"r+");
$modtime = fread($fp1,filesize($changelog));
fclose($fp1);
//轉檔函數
function phpfileedit($file){
global $dir_gb,$dir_utf8,$dir_utf81;
echo "source:$file<br>\n";
$fp = fopen("$file","r");
$old = fread($fp,filesize($file));
$old = str_replace('big5','UTF-8',$old);
$new1 = iconv("BIG5","UTF-8", $old);
fclose($fp);
//if($old<>$new1){
//寫入 UTF8
echo "utf8:$dir_utf8$file<br>\n";
$fp1 = fopen("$dir_utf8$file","w+");
fwrite($fp1,$new1);
fclose($fp1);
//}
}
//讀檔函數
function ListDir($dir){
global $modtime;
echo "<UL>\n";
$handle = opendir($dir);
while ($sdir=readdir($handle)){
if(is_dir("$dir/$sdir") and $sdir<> "." and $sdir<ListDir>$modtime){
echo "$sdir";
echo filemtime("$dir/$sdir");
echo "<br>\n";
if(substr($sdir,-3,3)=="php" or substr($sdir,-4,4)=="php3"){
phpfileedit("$dir/$sdir");
}
if(substr($sdir,-3,3)=="htm" or substr($sdir,-4,4)=="html"){
phpfileedit("$dir/$sdir");
}
if(substr($sdir,-3,3)=="ccs"){
phpfileedit("$dir/$sdir");
}
}
}
}
closedir($handle);
echo "</UL>";
}
//處理目錄
ListDir($dir_do);
//寫入完成時間
$fp1 = fopen($changelog,"w+");
fwrite($fp1,time());
fclose($fp1);
?>
//參數設定
$changelog = "utf8.log";
$dir_do = "source";
$dir_utf8 = "/var/www/html/target/";
//讀取上次轉換時間
$fp1 = fopen($changelog,"r+");
$modtime = fread($fp1,filesize($changelog));
fclose($fp1);
//轉檔函數
function phpfileedit($file){
global $dir_gb,$dir_utf8,$dir_utf81;
echo "source:$file<br>\n";
$fp = fopen("$file","r");
$old = fread($fp,filesize($file));
$old = str_replace('big5','UTF-8',$old);
$new1 = iconv("BIG5","UTF-8", $old);
fclose($fp);
//if($old<>$new1){
//寫入 UTF8
echo "utf8:$dir_utf8$file<br>\n";
$fp1 = fopen("$dir_utf8$file","w+");
fwrite($fp1,$new1);
fclose($fp1);
//}
}
//讀檔函數
function ListDir($dir){
global $modtime;
echo "<UL>\n";
$handle = opendir($dir);
while ($sdir=readdir($handle)){
if(is_dir("$dir/$sdir") and $sdir<> "." and $sdir<ListDir>$modtime){
echo "$sdir";
echo filemtime("$dir/$sdir");
echo "<br>\n";
if(substr($sdir,-3,3)=="php" or substr($sdir,-4,4)=="php3"){
phpfileedit("$dir/$sdir");
}
if(substr($sdir,-3,3)=="htm" or substr($sdir,-4,4)=="html"){
phpfileedit("$dir/$sdir");
}
if(substr($sdir,-3,3)=="ccs"){
phpfileedit("$dir/$sdir");
}
}
}
}
closedir($handle);
echo "</UL>";
}
//處理目錄
ListDir($dir_do);
//寫入完成時間
$fp1 = fopen($changelog,"w+");
fwrite($fp1,time());
fclose($fp1);
?>