<? Php
Error_reporting (0 );
Echo "\ n". "Enter the dictionary to be sorted:". "\ n ";
$ Dic = trim (fgets (STDIN ));
/***************************************
* Dictionary optimization tool lostwolf
* Remove dictionary duplication by adding a slash before each segment of data and removing the extra slash
*
**************************************/
$ File = file ($ dic );
$ Array = preg_replace ('/($ \ s * $) | (^ \ s * ^)/m', '', $ file); // clear empty rows
Foreach ($ arrayas $ key => $ r ){
$ Array [$ key] = trim ("/$ r"); // Add a slash and remove white space characters
}
$ New_array = preg_replace ('# ^ ([/] *) #', '/', $ array); // replace Multiple front slashes with one
$ New_array1 = array_values (array_unique ($ new_array); // eliminate duplicate rows
If(file_put_contents('new_file.txt ', join ("\ r \ n", $ new_array1 ))){
Echo "----------------------------------------". "\ r \ n ";
Echo "\ n". "finished! "." \ R \ n ";
Echo "the generated dictionary file is:". "\ r \ n ";
Echodirname (_ FILE _). DIRECTORY_SEPARATOR. "new_file.txt". "\ r \ n ";
Echo "----------------------------------------". "\ r \ n ";
}
Else {
Echo "----------------------------------------". "\ r \ n ";
Echo "error! "." \ R \ n ";
Echo "file not found! Check whether the dictionary exists! "." \ R \ n ";
Echo "----------------------------------------". "\ r \ n ";
}
?>