<?php
error_reporting(0);
@ini_set('memory_limit','-1');
set_time_limit(0);
echo" 去除文本重復工具"."\r\n\r\n";
echo"\n"."輸入要整理的文件:"."\n";
$dic=trim(fgets(STDIN));
/*while (!feof($dic)){
$file[]=stream_get_line($fp,65535,"\r\n");
}
*/
$file=file($dic);
$array=preg_replace('/($\s*$)|(^\s*^)/m','',$file); //消除空行
$new_array=array_values(array_unique($array));//消除重復行
$new_filename="new_". basename($dic);
if(file_put_contents("$new_filename",join("\r\n",$new_array))){
$num=count($file);
$new_num=count($new_array);
$counts=$num-$new_num;
$files=dirname(__FILE__).DIRECTORY_SEPARATOR.$new_filename;
echo<<<INFO
+----------------------------------------------+
| [+] 去除重復完畢! www.2cto.com |
| [+] 整理後的文件為:$files |
| [+] 原始字典數量:$num 行 |
| [+] 整理後為:$new_num 行 |
| [+] 共替換了$counts 行 |
+----------------------------------------------+
INFO;
}
else{
echo"------------------------------------------"."\r\n";
echo"[*] 錯誤!"."\r\n\r\n";
echo"[*] 找不到文件!請檢查輸入路徑是否存在!"."\r\n";
echo"------------------------------------------"."\r\n";
exit();
}
?>