对于这个问题,谁给个好的方法! file出这两个文件,进行比较,相同的就取一个,然后写入另一个文件中。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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; }这是我目前写的,我知道一定是错的,相同的取一个怎么操作? $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");} 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()); 求推荐学习php的好书? PHP一个很简单问题 希望高人指点 连数据库问题?? 关于根据浏览器访问的域名进行转向 PHP的乱码问题 域名访问空间问题 如何修改“动态”虚拟目录 100分求一个页面刷新问题,谢谢!!! 关于连接 MS SQL Server 的权限的问题。 关于mysql与php的数据读取问题的新手问题,大家都来讨论!!! 为什么 php3.0 以后的版本,addslashes不能去掉特殊字符 / 等
$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;
}
这是我目前写的,我知道一定是错的,相同的取一个怎么操作?
$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");
}
-------------------
[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());