Home >php教程 >php手册 >www字典优化脚本

www字典优化脚本

WBOY
WBOYOriginal
2016-06-13 10:45:511045browse

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";

}

 

 

?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn