您好我在命令中使用preg_match在我的文件中查找单词但是此函数找不到所有单词。
例如:我的服务器上有5个文件(pdf,doc和txt)。我试着找到“php”这个词,我有2个结果,但这个词在我的文档中至少出现了30次。为什么我只有2个结果?
另一个错误:行号并不总是正确的。
感谢您的帮助!
我的代码:
while ($donnees = $reponse->fetch())
{
$file=$donnees['filepath'];
$fname=$donnees['filename'];
$path="C:/xampp/htdocs/test".$file;
$lines = file($path);
foreach ($lines as $line_num => $line) {
if (preg_match_all('|\b' . preg_quote($mot) . '\b|i', $line)) {
echo "<center>Word ".$word." find at line ".($line_num+1)." in the file ".$fname."</center>";
}
}
}