See also pathinfo. Here's a simple example:
<?php
$dir = '.';
$fd = opendir($dir);
$types = array('jpg', 'jpeg', 'gif', 'png', 'bmp');
$html = '';
while ($file = readdir($fd)) {
$path = pathinfo($file);
if (is_readable("$dir/$file") && in_array(strtolower($path['extension']), $types)) {
$html .= "<p><img src='$dir/$file' alt='$file'></p>";
}
}
?>