<?php class ImgFilter extends FilterIterator { public function accept() { return preg_match('@\.(gif|jpe?g|png)$@i',$this->current()); } } foreach (new ImgFilter(new DirectoryIterator('/www/public_html/images')) as $img) { print "<img src='".htmlentities($img)."'/>\n"; } ?>