本帖最后由 everydayrun1 于 2011-08-04 16:43:52 编辑

解决方案 »

  1.   

    两个文件的行数一样么?且一一对应?<?php
      $content1=file_get_content("A.txt");
      $array1=explode('\n',$content1);
      $content2=file_get_content("B.txt");
      $array2=explode('\n',$content2);
      for($i=0;$i<count($array1);$i++)
         $contentNew.=$array2[$i].$array1[$i]."\n";
      file_put_contents("aa.txt",$contentNew);
    ?>
      

  2.   

    忘了在循环之前加上初始化语句
      $contentNew='';
      

  3.   

    假定两文件行数一致,并无空行function foo($a, $b) {
      return trim($a) . trim($b) . ';';
    }$a = file('文件A');
    $b = file('文件B');$c = array_map('foo', $b, $a);echo join(PHP_EOL, $c);
      

  4.   


    $a = @file_get_contents('a.txt');
    $a = explode("\r\n",trim($a));
    $b = @file_get_contents('b.txt');
    $b = explode("\r\n",trim($b));
    $combination = array();
    foreach((array)$a as $key=>$value){
    $combination[] = $b[$key].$value.';';
    }
    implode("\r\n",$combination);
    @file_put_contents('c.txt',$combination);还是版主的简洁