Jump to content

BBCode Parser


ajicles

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.