Here is a BB Code that I would like to convert to HTML and then Back if necessary on a bulletin board. I have a JavaScript that prompts for 5 pairs of key-value and yeilds:
[TABLE BD=5 BDC=blue BGC=azure CP=5 CS=3]
I would like to turn this code generated by the 5 prompts to the following so it will appear in the preview of posted message.
<TABLE BORDER = "5" BORDERCOLOR = "blue" BGCOLOR= "azure" CELLPADDING = "5" CELLSPACING = "3">
I almost had it I think but it missed a < and then the more I messed with it the worse it got using preg_replace.
I can easily convert [TABLE] {/TABLE to <TABLE> </TABLE> with this conversion:
$txt = preg_replace( "#\[table\](.+?)\[/table\]#is", "<TABLE>\\1</table>", $txt );
// and unconvert with
$txt = preg_replace( "#(<table>)(.+?)(</table>)#is","[table\]\\1\[/table\]", $txt );
// I can also convert these two td attributes with
$txt = preg_replace( "#\[td c=(\S+?)\s*\](.+?)\[/td\]#is", "<td colspan=\"\\1\">\\2</td>", $txt );
$txt = preg_replace( "#\[td r=(\S+?)\s*\](.+?)\[/td\]#is", "<td rowspan=\"\\1\">\\2</td>", $txt );
// and unconvert with
$txt = preg_replace( "#(<td colspan=\"(.+?)\">)(.+?)(</td>)#is","[td c=\\2\]\\3\[/td\]", $txt );
$txt = preg_replace( "#(<td rowspan=\"(.+?)\">)(.+?)(</td>)#is","[td r=\\2\]\\3\[/td\]", $txt );
I just can't seem to get how to convert 5 attributes to HTML and then back to BB Code, what do I need to do to make it work?