$arr=preg_split("/\s/",$readTxtContent);
$resultTxt=implode("\n\r",array_unique($arr));
然后将$resultTxt覆盖写入文件

解决方案 »

  1.   

    <?
    $buf = fread(fopen("test.txt","r"),filesize("test.txt"));
    $array = explode("\n",$buf);
    $temp = array();
    for($i=0;$i<count($array);$i++)
       if(!array_search($array[$i],$temp)) array_push($temp,$array[$i]);
    $buf = implode("\n",$temp);
    $f = fopen("test.txt","w");
    fwrite($f,$buf,count($buf));
    ?>差不多是这样吧,没测试过。祝你好运。呵呵~~~~~~~~~
      

  2.   

    <?
    $fileName="test.txt";
    $arr=file($fileName);
    $fp=fopen($fileName,"w");
    fputs($fp,implode("",array_unique($arr)));
    fclose($fp);
    ?>