Jump to content

bbcode, preg replace


desithugg

Recommended Posts

<?
function bbcode($replace)
{
$bbcode = array(
"'\[center\](.*?)\[/center\]'is" => "<center>\\1</center>",
"'\[left\](.*?)\[/left\]'is" => "<div style='text-align: left;'>\\1</div>",
"'\[right\](.*?)\[/right\]'is" => "<div style='text-align: right;'>\\1</div>",
"'\[pre\](.*?)\[/pre\]'is" => "<pre>\\1</pre>",
"'\[b\](.*?)\[/b\]'is" => "<b>\\1</b>",
"'\[quote\](.*?)\[/quote\]'is" => "<div class='top'><b>Quote:</b><hr>\\1</div>",
"'\[i\](.*?)\[/i\]'is" => "<i>\\1</i>",
"'\[u\](.*?)\[/u\]'is" => "<u>\\1</u>",
"'\[s\](.*?)\[/s\]'is" => "<del>\\1</del>",
"'\[move\](.*?)\[/move\]'is" => "<marquee>\\1</marquee>",
"'\[url\](.*?)\[/url\]'is" => "<a href='\\1' target='_BLANK'>\\1</a>",
"'\[url=(.*?)\](.*?)\[/url\]'is" => "<a href=\"\\1\" target=\"_BLANK\">\\2</a>",
"'\[img\](.*?)\[/img\]'is" => "<img border=\"0\" src=\"\\1\">",
"'\[img=(.*?)\]'" => "<img border=\"0\" src=\"\\1\">",
"'\[email\](.*?)\[/email\]'is" => "<a href='mailto: \\1'>\\1</a>",
"'\[size=(.*?)\](.*?)\[/size\]'is" => "<span style='font-size: \\1;'>\\2</span></a>",
"'\[font=(.*?)\](.*?)\[/font\]'is" => "<span style='font-family: \\1;'>\\2</span></a>",
);
$replace = preg_replace(array_keys($bbcode), array_values($bbcode), $replace);
return $replace;
}
?>

Well that's my bbcode function and it works fine no problem with it but I wanted to add a list function where theres bullets are added and the text is done in a list format like below

  • one
  • two
  • thre

heres the bb code for it

[list]
[*]one
[*]two
[*]threeeeeee
[/list]

But I'm not so sure how I can preg replace to add bullets to that.

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/48513-bbcode-preg-replace/
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.