【问题标题】:Iterate over specific files in a directory遍历目录中的特定文件
【发布时间】:2010-06-26 04:22:26
【问题描述】:

我需要使用 glob 获取所有以“t_”开头的图像。我应该使用什么模式来做到这一点?

        //get any image files that begin with "t_" -- (t_image.jpg) not (image.jpg)
        $images = glob("" . $dir . "*.jpg");

        foreach($images as $image)
        {
            echo $image;
        }

【问题讨论】:

    标签: php regex glob


    【解决方案1】:
    foreach (glob("t_*.jpg") as $filename) {
        echo "$filename size " . filesize($filename) . "\n";
    }
    

    这意味着:

    foreach (glob("$dir/t_*.jpg") as $filename) {
        echo "$filename size " . filesize($filename) . "\n";
    }
    

    另见:

    http://ca2.php.net/manual/en/function.glob.php

    【讨论】:

      猜你喜欢
      • 2019-01-16
      • 2013-05-02
      • 2015-09-06
      • 2013-01-27
      • 2012-10-05
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      相关资源
      最近更新 更多