【问题标题】:Search in subfolders在子文件夹中搜索
【发布时间】:2012-07-06 01:05:41
【问题描述】:

我需要将搜索扩展到子文件夹。

我需要一些帮助来修改和添加这个脚本的功能:

<?php 
if(isset($_GET['s']) and $_GET['s'] != '') { 
    $dir = 'dir/sub-dir'; 
    $ext = '.htm'; 
    $search = $_GET['s']; 
    $results = glob("$dir/*$search*$ext"); 
    if(count($results) != 1) { 
        foreach($results as $item) { 
            echo "<li><a href='$item'>$item</a></li>\r\n";     
        } 
    } 
    if(count($results) == 1) { 
        $item = $results[0]; 
        echo "<li color='blue'><a href='$item'>$item - only result</a></li>\r\n"; 
    } 
    if(count($results) == 0) { 
       echo "<li>no results to display</li>\r\n";    
    } 
} 
else { 
?> 
<form action=''> 
<input name='s'> 
<input type='submit'> 
</form> 
<?php 
} 
?> 

【问题讨论】:

    标签: php search subdirectory


    【解决方案1】:

    我在我的网站上的一个页面中做了类似的事情,我尝试使用一些新的递归目录列表函数,它们对我的应用程序不起作用,但它们可能对你有用。检查此页面。 http://php.net/manual/en/class.recursivedirectoryiterator.php

    PHP 中内置了其他类似的函数,它们链接到该页面。

    对我来说,我使用 ajax 来调用我围绕 scandir() 构建的 php 函数,并将它传递给要列出的下一个文件夹。这很好用,因为它始终是当前目录的子文件夹。这样我也可以让它在嵌套列表中展开。

    【讨论】:

    • 谢谢约翰,我会尝试设置。
    猜你喜欢
    • 1970-01-01
    • 2017-06-04
    • 2015-08-04
    • 2021-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多