0
我无法弄清楚如何让grep返回文件中找到的所有行。它计算正确的数字,但只打印最后一场比赛。grep不返回所有匹配行
$found = array();
$term = escapeshellarg(self::$term);
foreach(self::$files as $file)
{
if($count = exec("grep -i -c ".$term." ".$file))
{
$lines = exec("grep -i -n ".$term." ".$file);
$found[] = array('count'=>$count,'lines'=>$lines,'file'=>str_replace(self::$dir, '', $file));
}
}
self::$files = $found;
比方说self::$term = 'console.log'
。它在一个特定文件中找到三个匹配,这是正确的(该术语出现在测试文件的第16,21和31行),但$lines
仅打印:31: console.log(response);
。
我错过了什么?
有没有其他的选择,因为passthru()似乎回应结果? –
没关系。使用'ob_start()','$ lines = ob_get_content()'和'ob_end_clean()'是我需要做的。谢谢! –