Jump to content

bbcode function


php_begins

Recommended Posts

Right now i used the following code to convert bbcode to html/php.

i also need to incorporate QUOTE=name and URLS as well..how do i do that?

 

function bbcode_format ($str) {
$str = htmlentities($str);

$start = array(
'/\[b\](.*?)\[\/b\]/is', 
'/\[i\](.*?)\[\/i\]/is', 
'/\[u\](.*?)\[\/u\]/is',
'/\[a\=(.*?)\](.*?)\[\/a\]/is',	
'/\[color\=(.*?)\](.*?)\[\/color\]/is',	
'/\[img\](.*?)\[\/img\]/is',
'/\[header\](.*?)\[\/header\]/is'
);

$finish = array(
'<strong>$1</strong>',
'<em>$1</em>',
'<u>$1</u>',
'<a href="$1">$2</a>',
'<span style="color: $1">$2</span>',
'<img src="$1" />',
'<span class="h3">$1</span>'
);


$str = preg_replace ($start, $finish, $str);

return $str;
}

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