Home >Backend Development >PHP Tutorial >Simple removal of text duplication_PHP tutorial
error_reporting(0);
echo"n"."Enter the files to be sorted:"."n";
$dic=trim(fgets(STDIN));
$file=file($dic);
$array=preg_replace('/($s*$)|(^s*^)/m','',$file); //Eliminate blank lines
$new_array=array_values(array_unique($array));//Eliminate duplicate rows
$new_filename="new_". basename($dic); www.2cto.com
if(file_put_contents("$new_filename",join("rn",$new_array))){
echo"------------------------------------------------"."rn";
echo "n"."Removal of duplicates completed!"."rn" ;
echo "The file after removing duplicates is: "."rn";
echo dirname(__FILE__).DIRECTORY_SEPARATOR."$new_filename"."rn";
echo"------------------------------------------------"."rn";
}
else{
echo"------------------------------------------------"."rn";
echo "Error!"."rn";
echo "File not found! Please check if the input path exists!"."rn";
echo"------------------------------------------------"."rn";
exit();
}
?>
Excerpted from http://hi.baidu.com/nginxshel