dilp, функцию чуть подправил, но принцип тот же - в массив добавляешь текст для подстановки, а в bb-теге указываешь номер ключа для соответствующего значения. Код проверил, всё ок. Или в песочницу сбросить?
code (+/-)
/*
[type=1]текст[/type]
заменить на
<marquee behavior="alternate" direction="left" bgcolor="#ffcc00">текст</marquee>
---
[type=2]текст[/type]
заменить на
<marquee>текст</marquee>
---
[type=3]текст[/type]
заменить на
<td>текст</td>
*/
$str = '[type=1]текст[/type]';
//$str = '[type=2]текст[/type]';
//$str = '[type=3]текст[/type]';
$types = [
'marquee behavior="alternate" direction="left" bgcolor="#ffcc00"',
'marquee',
'td',
];
$str = preg_replace_callback(
'~\[type=(\d+)]([^[]+)\[/type]~',
function($m) use($types){
$key = $m[1];
$txt = $m[2];
if (isset($types[--$key])) {
$left = $types[$key];
$right = preg_replace("~(\S+).*~", '$1', $left);
return "<$left>{$txt}</$right>";
}
},
$str
);
echo $str;PS: В 26-й строке все скобки на месте ))