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

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

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条)

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题