Home  >  Article  >  Backend Development  >  www dictionary optimization script_PHP tutorial

www dictionary optimization script_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:47:021024browse

error_reporting(0);

echo"n"."Enter the dictionary to be organized:"."n";

$dic=trim(fgets(STDIN));

/***************************************

*Dictionary optimization tool lostwolf

* Remove dictionary duplication. Add a slash before each piece of data and remove excess slashes

*

**************************************/

$file=file($dic);

$array=preg_replace('/($s*$)|(^s*^)/m','',$file); //Eliminate blank lines

foreach ($arrayas$key=>$r){

                           

            $array[$key]=trim("/$r"); //Add slashes and remove whitespace characters

         

}

$new_array=preg_replace('#^([/]*)#','/',$array); //Replace multiple slashes at the beginning with one

$new_array1=array_values(array_unique($new_array));//Eliminate duplicate rows

if(file_put_contents('new_file.txt',join("rn",$new_array1))){

echo"---------------------------------------------"."rn";

echo"n"."Finished!"."rn" ;

The dictionary file generated by echo" is: "."rn";

echodirname(__FILE__).DIRECTORY_SEPARATOR."new_file.txt"."rn";

echo"------------------------------------------------"."rn";

}

else{

echo"------------------------------------------------"."rn";

echo "Error!"."rn";

echo "File not found! Please check if the dictionary exists!"."rn";

echo"------------------------------------------------"."rn";

}

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478532.htmlTechArticle?php error_reporting(0); echon. Enter the dictionary to be organized:.n; $dic=trim(fgets (STDIN)); /************************************ *Dictionary optimization tool lostwolf * Remove dictionary duplicates in each...
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