file出这两个文件,进行比较,相同的就取一个,然后写入另一个文件中。

解决方案 »

  1.   

    function to_all($txt_data1,$txt_data2){
      $data1=explode("\r\n",$txt_data1);
      $data2=explode("\r\n",$txt_data2);
      for($i=0;$i<count($data1);$i++){
    for($f=0;$f<count($data2);$f++){
      if($data1[$i]==$data2[$f]){
    $temp="";
      }else{
    $temp=$data1[$i];
      }
    }
    if($temp!="") $get_datas.=$temp."\r\n";
      }
      return $get_datas;
      
    }
    这是我目前写的,我知道一定是错的,相同的取一个怎么操作?
      

  2.   

    $file_a=file("a.txt");
    $file_b=file("b.txt");
    for($i=0;$i<count($file_a);$i++){
      if(!in_array($file_a[$i],$file_c){ 
        $file_c[$i]=$file_a[$i];
      }
    }
    $k=count($file_c);
    for($j=0;$j<count($file_b);$j++){
      if(!in_array($file_b[$j],$file_c){
        $file_c[$k]=$file_b[$j];
        k++;
      }
    }
    $file_d=fopen("c.txt","a+");
    for($i=0;$i<count($file_c);$i++){
      fwrite($file_d,$file_d[$i]."\n");
    }
      

  3.   

    a.htm
    -------------------
    [email protected]
    [email protected]
    [email protected]
    -------------------
    [email protected]
    [email protected]
    [email protected]
    -------------------
    function savefile()
    {
        $a = file('a.txt');
        $b = file('b.txt');
        $arr1 = array_merge($a,$b);
        $arr2 = array_unique($arr1);
        Return $arr2;
    }
    print_r(savefile());