error_reporting(0);
echo"\n"."輸入要整理的字典:"."\n";
$dic=trim(fgets(STDIN));
/***************************************
*字典最佳化工具lostwolf
* 去除字典重複 在每段資料前加斜杠並去除多餘斜杠
*
* *************************************/
$file=file($dic);
$array=preg_replace('/($\s*$)|(^\s*^)/m','',$file); //消除空行
foreach ($arrayas$key=>$r){
$array[$key]=trim("/$r"); //添加斜杠 並去除空白字元
}
$new_array=preg_replace('#^([/]*)#','/',$array); //將開頭多個斜杠替換成一個
$new_array1=array_values(array_unique($new_array));//消除重複行
if(file_put_contents('new_file.txt',join("\r\n",$new_array1))){
echo"------------------------------------------"."\r\n";
echo"\n"."整理完畢!"."\r\n" ;
echo"產生的字典檔案為:"."\r\n";
echodirname(__FILE__).DIRECTORY_SEPARATOR."new_file.txt"."\r\n";
echo"------------------------------------------"."\r\n";
}
else{
echo"------------------------------------------"."\r\n";
echo"錯誤!"."\r\n";
echo"找不到檔案!請檢查是否存在該字典!"."\r\n";
echo"------------------------------------------"."\r\n";
}
?>
http://www.bkjia.com/PHPjc/478532.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478532.htmlTechArticle?php error_reporting(0); echo\n.輸入要整理的字典:.\n; $dic=trim(fgets(STDIN)); /*************************************** *字典最佳化工具lostwolf * 去除字典重複 在每...