I own forums which I put news into which I put onto the front page of my website. But at the moment I'm stuck with the horible BBcode tags, so I guess I'll need to use regex (ugh) to get ride of them and replace them with the correct HTML. Anyone have any guidence on where to start with learning to use regex, since PHP manuals don't give any of the more complex syntax. I'm pretty sure if I looked around I could find someone to just give me the coding I need, but I'd rather work it out myself and learn by doing.
That's great, but for some reason phpBB puts a random unique code within the bbCode (http://www.allroundnews.co.uk]) so that wouldn't work much.
I wrote a tutorial on this, which you can find here: http://www.icemelon.com/tutorials/21/Create_Your_Own_BBCode.htm It uses the perl reg. exp. syntax functions, though - e.g. preg_match()
<?php $string = "[b:e3e53cad2b]Rawr, ^^;;"; $string = preg_replace("/(\[b:[a-zA-Z0-9]{0-10}\])/", "<b>", $string); echo $string; ?> PHP: What's wrong with that..? I was hoping the [b:....] would be replaced with <b>.
Thanks dtang4 ^^;; So I have the [b:4d785e5de5] converted to <b>. But now it doesn't seem to like me doing this: <?php $string = "[b:e3e53cad2b]Rawr, ^^;;[/b:5d5e887ftg]"; $string = preg_replace("/(\[b:[a-zA-Z0-9]{0,10}\])/", "<b>", $string); $string = preg_replace("/(\[/b:[a-zA-Z0-9]{0,10}\])/", "<b>", $string); echo $string; ?> PHP: Returns: Warning: preg_replace(): Unknown modifier 'b' in /home/httpd/vhosts/allroundnews.co.uk/subdomains/sheep/httpdocs/test.php on line 6 I need to convert [/b:5d5e887ftg] into </b>, but the backslash confuses the PHP, so I'm not sure how to escape it.
Hope this should help you. <?php $str = "[b:e3e53cad2b]Rawr, ^^;;[/b:5d5e887ftg]"; $str = preg_replace("/\[([biu])(:[a-zA-Z0-9]{0,10})*\]/i","<\\1>",$str); $str = preg_replace("/\[\/([biu])(:[a-zA-Z0-9]{0,10})*\]/i","</\\1>",$str); echo $str; ?> PHP:
Just use parse_bbcode built in vB. No need to reinvent the wheel! (assuming you have vbulletin) If not, your forum sofware certainly has a similar function. /** * Parse an input string with BB code to a final output string of HTML * * @param string Input Text (BB code) * @param bool Whether to parse smilies * @param bool Whether to allow HTML (for smilies) * * @return string Ouput Text (HTML) */ function parse_bbcode($input_text, $do_smilies, $do_html = false) PHP:
I'm not using forum soft ware, I'm just using bbCode as the submission code for my website since I want to strip HTML tags ^^;;
Ah, well, then I guess the other ideas will have to be developed. Rip the BBcode functions out of a GPL forum sofware package.