foreach ($images as $i) { $img = basename($i); $caption = substr($img, 0, strrpos($img, ".")); printf("
%s
", $img, $caption); }