【问题标题】:PHP Find files with specific name part in folderPHP在文件夹中查找具有特定名称部分的文件
【发布时间】:2018-01-23 14:50:25
【问题描述】:

有没有办法从 php 文件夹中获取所有具有特定名称的文件? 例如,我在文件夹中有下一个文件:

6546-da6sd.png 465-dasd.jpg 654-548484.jpg 第654章 654-sakj879.jpg 776-54fsdfs.png ....

我想获取所有以“654-”开头的文件(但不是第一个(6546-da6sd.png)) 谢谢!

【问题讨论】:

    标签: php regex file elasticsearch regex-lookarounds


    【解决方案1】:

    您可以使用glob() 和strpos() 赞:

    <?php
    $dir = 'files/';
    $key = '654-';//search key
    foreach (glob("$dir*") as $file) { 
        $file = str_replace($dir,'',$file);
        if (strpos($file, $key) == 0) {
            echo($file."<br>");
        }
    }
    ?>
    

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 2011-03-10
      • 2019-05-28
      • 1970-01-01
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多