|
Posted by Rik on 02/03/07 17:22
Well, another method then previously described, but something I just =
thought of: your idea to process tags only if they don't have nested tag=
s =
in them might work indeed... As long as a normal '[' is strictly forbidd=
en =
in the text itself. Again, without testing, so beware of typing errors, =
or =
other huge mistakes on my part :-)
<?php
/* first, process all self_closing tags */
function process_self_closing(){
//you logic for replacing
var_dump(func_get_args());
}
$string =3D =
preg_replace_callback('#\[([^\]|]+)(?:|([^\]|]+))*/]#','process_self_clo=
sing',$string);
/* match tags that don't have children */
function process_tags((){
//you logic for replacing
var_dump(func_get_args());
}
$count =3D 1;
while($count !=3D 0){
$string =3D =
preg_replace_callback('#\[([^\]|]+)(?:|([^\]|]+))*/]([^\[]*)\[/\1]#','pr=
ocess_tags',$string,-1,$count);
}
?>
Note: count parameter is available since PHP 5.1.0.
-- =
Rik Wasmus
[Back to original message]
|