Get a glob listing by expanding a comma separated list in curly braces

The following glob takes an array of extensions, implodes them by a comma, and then inserts that string into curly braces. The glob function itself needs the GLOB_BRACE setting.

This glob will return all entries in a directory of the form: *.txt, *.zip, *.gif, *.jpg and *.png.

<?php
$config = array("txt", "zip", "gif", "jpg", "png");
$a_files = glob("*.{" . implode(",",$config['allowed_extensions']) . "}",GLOB_BRACE);
print_r($a_files);
?>

Page Comments (Click to edit)






[Click to add or edit comments])

Please prepend comments below including a date

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Have a nice day.