doudi7570 2017-06-21 10:38
浏览 195
已采纳

在包含文件的文件夹中查找关键字

I use a script that allows me to find a file in a folder whose keyword matches the word chosen by the user, but the problem is that the result does not match the search keyword.

For example the user searches for the word "Hyper-v" and either it comes out files that have no relationship or it comes out nothing.

Thank you for your help

$findThisString = stripcslashes($_POST["recherchemotcle"]);
$path = "tuto";
$dir = opendir($path);

while (false !== ($file = readdir($dir)))
{   
            $data = file_get_contents($path . '/' . $file);

            if (stripos($data, $findThisString) !== false)
            {
              echo ''.$file.' <br/>';
            }

}

$dir->close();
  • 写回答

2条回答 默认 最新

  • douwen6274 2017-06-21 12:40
    关注

    Try this,

    $findThisString = stripcslashes($_POST["recherchemotcle"]);
    $path = "tuto";
    $dir = opendir($path);
    
    while (false !== ($file = readdir($dir)))
    {           $data = glob($path . '/' . $file);
    
                if (stripos($data[0], $findThisString) !== false)
                {
                  echo ''.$file.' <br/>';
                }
    
    }
    
    closedir($dir);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?