我想逐行读取一个文件,并在 unıx 上使用 php 脚本在每一行中搜索另一个文件。然后将结果写入另一个文件。
我该怎么做? 我的意思是;
文件1:
192.168.1.2
192.168.1.3
192.168.1.5
文件2:
.....
192.168.1.3
192.168.12.123
192.168.34.56
192.168.1.5
....
文件3:
192.168.1.3
192.168.1.5
我想读取文件 1 的每一行并搜索文件 2 的每一行。如果我有匹配的搜索结果写入文件 3。
最佳答案
<?php
$file1 = file('file1', FILE_SKIP_EMPTY_LINES);
$file2 = file('file2', FILE_SKIP_EMPTY_LINES);
$file3Content = implode('', array_intersect($file1, $file2));
file_put_contents('file3', $file3Content);
关于php - 逐行读取文本文件并在每一行中搜索另一个文件 php 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24179590/