首页 > php代码 > php 去除txt文本重复数据

php 去除txt文本重复数据

因为是

13503594262

13503594262

13243694429

13503594262

13880561750

13404776999

15675167006

这种格式,所有我们就用file把文本直接载入到数组

$array = file($file);

用print_r输出

Array

(

    [0] => 13688179054

    [1] => 13652179481

    [2] => 13545684587

    [3] => 13787008977

    [4] => 13077337442

    [5] => 15900780969

    [6] => 15900780969

    [7] => 13077337442

    [8] => 13077337442

    [9] => 13830933836

    [10] => 13640292942

    [11] => 13582045025

    [12] => 13522725381

    [13] => 13522725382

    [14] => 13512345678

    [15] => 13001831752

    [16] => 13737657988

    [17] => 13737657988

    [18] => 13636399773

    [19] => 13661726563

    [20] => 13554797552

    [21] => 13919571298

    [22] => 15809480888

    [23] => 13925810190

    [24] => 13631811119

    [25] => 13524620464

    [26] => 13077337442

    [27] => 13077337442

    [28] => 13077337442

    [29] => 13077337442

*/

$zhi = file('www.phprm.com.txt');
print_r($zhi);
die();
$chuzhi = array_values(array_unique($zhi));
$str ='';
for($i=0;$i<count($chuzhi);$i++){
 $str .= $chuzhi[$i];
}
//保存到字符串里,再用fopen写入到文本
$hold = fopen('12.txt','w+');
fwrite($hold,$str);
fclose($hold);

/*

http://www.phprm.com文本内容

13503594262

13503594262

13503594262

13503594262

13243694429

13503594262

13880561750

13404776999

15675167006


本文地址:http://www.phprm.com/code/a500b1b77e263b4fbd3724f271486cbd.html

转载随意,但请附上文章地址:-)

标签:none

发表留言