convert BBCode to HTML

convert BBCode to HTML
BBCode is an abbreviation for Bulletin Board Code, the lightweight markup language used to format posts in many message boards. It is also called forum codes. The available tags are usually indicated by rectangular brackets surrounding a keyword, and they are parsed by the message board system before being translated into a markup language that web browsers understand, usually HTML or XHTML.<?php
function bbcode_format ($str) {
$str = htmlentities($str);

$simple_search = array(
‘/\[b\](.*?)\[\/b\]/is’,
‘/\[i\](.*?)\[\/i\]/is’,
‘/\[u\](.*?)\[\/u\]/is’,
‘/\[url\=(.*?)\](.*?)\[\/url\]/is’,
‘/\[url\](.*?)\[\/url\]/is’,
‘/\[align\=(left|center|right)\](.*?)\[\/align\]/is’,
‘/\[img\](.*?)\[\/img\]/is’,
‘/\[mail\=(.*?)\](.*?)\[\/mail\]/is’,
‘/\[mail\](.*?)\[\/mail\]/is’,
‘/\[font\=(.*?)\](.*?)\[\/font\]/is’,
‘/\[size\=(.*?)\](.*?)\[\/size\]/is’,
‘/\[color\=(.*?)\](.*?)\[\/color\]/is’,
);

$simple_replace = array(
‘<strong>$1</strong>’,
‘<em>$1</em>’,
‘<u>$1</u>’,
‘<a xhref=”$1″ mce_href=”$1″>$2</a>’,
‘<a xhref=”$1″ mce_href=”$1″>$1</a>’,
‘<div style=”text-align: $1;”>$2</div>’,
‘<img xsrc=”$1″ mce_src=”$1″ />’,
‘<a xhref=”mailto:$1″ mce_href=”mailto:$1″>$2</a>’,
‘<a xhref=”mailto:$1″ mce_href=”mailto:$1″>$1</a>’,
‘<span style=”font-family: $1;”>$2</span>’,
‘<span style=”font-size: $1;”>$2</span>’,
‘<span style=”color: $1;”>$2</span>’,
);

// Do simple BBCode’s
$str = preg_replace ($simple_search, $simple_replace, $str);

// Do <blockquote> BBCode

return $str;
}

?>

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.