en el manual de PHP, si
lees
salen ejemplos, de como usar ciertas funciones... incluso, hay uno muy bueno, que sirve para etiquetas anidadas....
http://php.net/preg_replace_callback Código PHP:
<?php
$input = "plain[indent] deep[indent] deeper [/indent]deep [/indent]plain";
function parseTagsRecursive($input)
{
$regex = '#\[indent]((?:[^[]|\[(?!/?indent])|(?R))+)\[/indent]#';
if (is_array($input)) {
$input = '<div style="margin-left: 10px">'.$input[1].'</div>';
}
return preg_replace_callback($regex, 'parseTagsRecursive', $input);
}
$output = parseTagsRecursive($input);
echo $output;
?>
suerte!