douhao6271 2014-11-23 11:50
浏览 45
已采纳

使用大写+小写混合词的文件夹中的递归搜索?

hello guys i have search a lot, and iam trying to make that working. The following script searches recursive for the files into all folders.

if(isset($_POST['cmdsearch']))
{
$search = $_POST['search'];
    if (@get_magic_quotes_gpc())
    {
    $search = stripslashes($search);
    }
$it = new RecursiveDirectoryIterator("jpg");

foreach(new RecursiveIteratorIterator($it) as $file) 
    {
       if (false !== stripos($file, $search))
       {

       echo "<a style='padding:10px 10px 5px 5px; text-decoration:none; line-height:15px;' class='smamal' target='_blank' href='http://www.domain.com/files/";
       echo $file;
       echo "'>";
       echo "www.domain.gr/files/";
       echo $file;
       echo "</a>";
       echo "<br />";
       }
   }  
}
else
{
echo "<p></p>";
}

WHAT I WANT TO ADD:

  1. [Important] I want to search in files both for Upper & Lower Case letters. example: right now if you search for "Drink" it gives only "Drink" not "drink".
  2. Also if it is possible to search also for the 4 first letters of a given word example: search for "headphones" results= "headphones" "headline" "headless" etc...

i am trying to add into the code something like this

/\b([a-z]+[A-Z]+[a-zA-Z]*|[A-Z]+[a-z]+[a-zA-Z]*)\b/

thanks for your time.

  • 写回答

2条回答 默认 最新

  • dowjgrm6787 2014-11-23 13:19
    关注

    Why don't convert search and filename to lowercase. This way you will get case-insensitive matches. Another option is to set the flag i for case-insensitive matches in regular expressions. For matching the first four characters use substr on both strings before comparing them.

    If you really search large datasets think about using something like elastic search. This will even provide you fuzzy search (e.g. heaflines will also return results for headlines).

    http://www.elasticsearch.org/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大