Glob examples

Shows how to use the glob function to read directory listings as with "opendir" - just easier :-)

$dir = './';
foreach(glob($dir.'*.txt') as $file) {
    print $file . "\n";
/* returns: 
** other examples:
// also possible:
$files = glob('*.*');
// This shows how to use the GLOB_BRACE flag:
$images = glob("images/{*.jpg,*.gif,*.png}", GLOB_BRACE);
/* Valid flags:
see manual for more info
Snippet Details

Sorry folks, comments have been deactivated for now due to the large amount of spam.

Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!

Older comments:

MD May 09, 2011 at 14:47
My glob() Function Is Not Accepting Path
In Array.

I Want Set Path Dynamically From Database But It's Not Working.
My Coad As Follwing I Need Help.

$slIm1=mysql_query("select ImgPath from subcategory_2
where SubCategory='".$id."'");

//Get Path In Array.
echo "<img src='".$num."'>";

Jonas January 20, 2011 at 14:28
Thanks LED!

When I can find some time beside my job I'll post some more snippets in 2010.
LED January 18, 2011 at 06:01
No replies for 2010 so thought I'd be the 1st for 2011...Thanks for the past J.J. and hope to see more :)
bassman February 19, 2009 at 23:21
Very good examples, better then in the manual.
Thank you Jonas
vijay December 01, 2008 at 11:59
very super explain this function