<?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);
//文件查找每一行的字符串与指定文件中的每一行的字符串比较
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);
本文介绍了一个使用PHP编写的简单脚本,该脚本能够逐行比较两个文本文件的内容,并输出存在于第一个文件中但不在第二个文件中的条目。通过实际例子演示了如何读取文件、对比数据以及展示结果。

被折叠的 条评论
为什么被折叠?



