实际上恕我直言,我会说它是以下内容:
原文链接:https://www.f2er.com/php/137598.html$result = preg_grep($pattern,file($path));
如果您需要(递归地)对一组文件执行此操作,还有glob
和foreach或(递归)DirectoryIterator或GlobIterator
Docs,而不是忘记RegexIterator
Docs.
SplFileObject和RegexIterator的示例:
$stream = new SplFileObject($file); $grepped = new RegexIterator($stream,$pattern); foreach ($grepped as $line) { echo $line; }
输出(包含$pattern的$file的所有行):
$grepped = new RegexIterator($stream,$pattern); foreach ($grepped as $line) { echo $line; }