使用PHP从文本文件中提取特定数据

使用PHP从文本文件中提取特定数据,php,Php,我有一个3500网址的文本文件。此文本文件由2500.com域URL和1000.es域URL组成,格式如下: 如何使用PHP刮取完整的.es URL并将其提取到新的文本文件中?这可能会有所帮助 /*read whole file into array*/ $linkList = file("path/to/file"); /*filter array*/ $filteredList = preg_grep("/\.es$/", $linkList); /*write it back to fi

我有一个3500网址的文本文件。此文本文件由2500.com域URL和1000.es域URL组成,格式如下:

如何使用PHP刮取完整的.es URL并将其提取到新的文本文件中?

这可能会有所帮助

/*read whole file into array*/
$linkList = file("path/to/file");
/*filter array*/
$filteredList = preg_grep("/\.es$/", $linkList);
/*write it back to file*/ 
file_put_contents('newFile.txt', implode("\n", $filteredList));

这里有一个方法

$source = fopen("inputfile", "r");
$destination = fopen("outputfile", "w");

if ($source && $destination) {
    while (($line = fgets($source))) {
        if (strpos($line,'.es')) {

            fwrite($destination, $line); 
        }

    }
    fclose($source);
    fclose($destination);
} else {
    // error opening the file.
} 

更努力地搜索:这不是我要找的。谢谢,伙计,非常感谢。