ajicles Posted August 31, 2010 Share Posted August 31, 2010 I was wonder how I could make some BBcode for my messaging system I made for a website. I made some simple ones like just by replace [ red ] with font color etc. I want to know how to do something like this: [ url = http://google . ca] Google [ / url ] without the spaces. ~AJ Link to comment https://forums.phpfreaks.com/topic/212133-bbcode-parser/ Share on other sites More sharing options...
jcbones Posted August 31, 2010 Share Posted August 31, 2010 A very simple bbcode function. function bbcode($content) { $content = preg_replace("~\[b\](.+?)\[\/b\]~i", "<b>$1</b>", $content); $content = preg_replace("~\[i\](.+?)\[\/i\]~i", "<i>$1</i>", $content); $content = preg_replace("~\[u\](.+?)\[\/u\]~i", "<u>$1</u>", $content); $content = preg_replace("~\[img\](.+?)\[\/img\]~i", "<img src=\"$1\" alt=\"\" />", $content); $content = preg_replace("~\[url\](.+?)\[\/url\]~i", "<a href=\"$1\">[Link]</a>", $content); $content = preg_replace("~\[url=http://(.+?)\](.+?)\[\/url\]~i", "<a href=\"$1\">$2</a>", $content); $content = str_replace("\n", '<br />', $content); return($content); } It accepts the following: [url]http://google.com[/url] [url=http://google.com]Custom Text[/url] [img=http://mysite.com/images/somepic.jpg] [b]Bold[/b] [u]Underline[/u] [i]Italics[/i] Link to comment https://forums.phpfreaks.com/topic/212133-bbcode-parser/#findComment-1105470 Share on other sites More sharing options...
ajicles Posted August 31, 2010 Author Share Posted August 31, 2010 Thank you very much Link to comment https://forums.phpfreaks.com/topic/212133-bbcode-parser/#findComment-1105488 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.