2010-06-26 112 views
1

我需要使用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; 
     } 

回答

4
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