Iterate over specific files in a directory

2019-02-27 18:20发布

I need to get all images that begin with "t_" using glob. What pattern should I use to do this?

        //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条回答
不美不萌又怎样
2楼-- · 2019-02-27 18:52
foreach (glob("t_*.jpg") as $filename) {
    echo "$filename size " . filesize($filename) . "\n";
}

This implies:

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

See also:

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

查看更多
登录 后发表回答