$text = preg_replace_callback('#\[im\](.*?)\[/im\]#si', $getImages, $text);
function getImages($matches) {
$array = array();
$dir = opendir('../'.$matches[1].'/');
while ($file = readdir($dir)) {
if (($file != '.') && ($file != "..")) {
$array[] = $file;
}
}
closedir($dir);
$total = count($array);
$end = $start + $kmess;
for ($i = $start; $i < $end; $i++) {
$t = '<img src="http://сайт.ru/'.$matches[1].'/1.gif" /><br/>';
}
return $t;
}