Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

BBCode --> HTML table

  •  05-13-2011, 2:02 PM

    BBCode --> HTML table

    Hello

    I have a forum that allows custom bulletin board code to be executed through PHP files. Now I'm trying to construct a html table tag from some kind of 'template'. A pipe symbol designates the delimiter between individual cells of the table and a linebreak designates that a new table row should be inserted. Ofcourse, there is no way to determine how much cells and rows a user will insert into the table, so I need a working regex to find and replace every occurance of the '|' symbol and every linebreak within the table bbcode.

    Pipe symbol (|) should become: </td><td>
    Linebreak (\n) should become: </td></tr><tr><td>

     So far, I have this code which puts the 'container' around the text, but I have no idea how I would go about replacing the actual content. I'm new to regex writing.
    In this code, {$_tag} = table. It is in a foreach loop, because there can be multiple bbcode tags which do the same thing.

    $txt = preg_replace( "/\[{$_tag}\](.+?)\[\/{$_tag}\]/is", "<table class=\"bbcode_table\"><tr class=\"first_row\"><td>\\1</td></tr></table>", $txt );

     

    Filed under: , , ,
View Complete Thread