Simple removal of text duplication_PHP tutorial

WBOY
Release: 2016-07-13 17:47:58
Original
1235 people have browsed it

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478473.htmlTechArticle?php error_reporting(0); echon. Enter the file to be sorted:.n; $dic=trim(fgets (STDIN)); $file=file($dic); $array=preg_replace(/($s*$)|(^s*^)/m,,$file); //Eliminate blank lines $new_array=a ...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template