$text = 'ФОТО [im]bonus[/im]';
$text = preg_replace_callback('#\[im\](.*?)\[/im\]#si',
create_function(
'$matches',
'$array = array();'
'$dir = opendir("http://сайт.ru/$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;'
)
, $text);
echo $text;