我想在目录中的一个或多个文本文件中找到特定的文本字符串,但我不知道如何做。我已经用谷歌搜索了很长时间,但什么也没找到。因此,我想问问你们,我该如何解决这个问题?
提前致谢。
最佳答案
如果它是你正在运行的 Unix 主机,你可以在目录中对 grep
进行系统调用:
$search_pattern = "text to find";
$output = array();
$result = exec("/path/to/grep -l " . escapeshellarg($search_pattern) . " /path/to/directory/*", $output);
print_r($output);
// Prints a list of filenames containing the pattern
关于php - 在 PHP 中查找多个 TXT 文件中的特定文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8032312/