关于php文件查找每一行的字符串与指定文件中的每一行的字符串

来源:互联网 发布:郑州网络诈骗最新新闻 编辑:程序博客网 时间:2024/05/16 01:42
<?php
//文件查找每一行的字符串与指定文件中的每一行的字符串比较
  function ratherFile($file,$paper){   
    $handle  = fopen($file, "r");
    $handleTwo = fopen($paper, "r");
    while (!feof ($handle))
    {
      $buffer  = fgets($handle);  
      $username = trim($buffer);
      rewind($handleTwo);
      while (!feof ($handleTwo)){
        $bufferTwo  = fgets($handleTwo);  
        $userTwo = trim($bufferTwo);
        if($username==$userTwo){
            echo $username."<br/>";
            break;
        }
      }
    }
    fclose ($handleTwo);
    fclose ($handle);
  }

  $fileOne = dirname(__FILE__)."/bad.txt";
  $fileTwo = dirname(__FILE__)."/ok.txt";

  ratherFile($fileOne,$fileTwo);
原创粉丝点击