Etienne Kneuss

home » repository » php » sample » BB.php
Tree:
school
mp3
php
sample
sort.php
bitmask.php
disable_magic_quotes.php
BB.php
regex_urls.php
highlight_patch.php
publications
Math_Derivative
Math_Expression
ircbot
php.net
images
dump

Source code raw phps

    <?php /**  * Nice recursive way to parse BB tags  */ $input = "my html code [u] ooh a tag [i] deepe[b] deeperdeeper tag [/b]r tag [/i] foo bar! [/u] my html normal code";  function parseTagsRecursive($input) {     if (is_array($input) && isset($input[2])) {         switch($input[1]) {             case 'u':                 $format = '<span style="text-decoration:underline">%s</span>';                 break;                              case 'i':                 $format = '<span style="font-style:italic">%s</span>';                 break;             case 'b':                 $format = '<span style="font-weight:bold">%s</span>';                 break;         }              $input = sprintf($format, $input[2]);     }     return preg_replace_callback('#\[(u|i|b)]((?:[^[]|\[(?!/?\1])|(?R))+)\[/\1]#', 'parseTagsRecursive', $input); } $output = parseTagsRecursive($input); echo $output;

Comments

02.07.2006 #1 sutmin

Nice script colder :)

I just tested it and works perfectly. When not closing a tag. Example: [b] string it just outputs [b] and not bold :)

Add a comment

Username:

Spam Challenge: 6+16=?

Comment: