Another one for the Code Library: BBCode has been in common use on most forums for years, it is a way of allowing users to markup their posts witout using HTML. I have created a form of BBCode called ICCode, I created this version because I wanted to use BBCode not to markup users posts but to markup articles for a website
ICode includes the basic markup found in BBCode but also adds the sh tag for sub headings and the abbr tag for abbreviations. There are plans to add further tags later on. These additions make it far more accessible than traditional BBCode.
Code:
function ICode($str)
{
$str = htmlentities($str,ENT_NOQUOTES);
$simple_search = array(
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[p\](.*?)\[\/p\]/is',
'/\[sh\](.*?)\[\/sh\]/is',
'/\[list\](.*?)\[\/list\]/is',
'/\[item\](.*?)\[\/item\]/is',
'/\[img\=\"(.*?)\"\](.*?)\[\/img\]/is',
'/\[url\=\"(.*?)\"\](.*?)\[\/url\]/is',
'/\[abbr\=\"(.*?)\"\](.*?)\[\/abbr\]/is',
'/\[code\](.*?)\[\/code\]/is'
);
$simple_replace = array(
'<strong>$1</strong>',
'<em>$1</em>',
'<u>$1</u>',
'<p>$1</p>',
'<h3>$1</h3>',
'<ul>$1</ul>',
'<li>$1</li>',
'<img src="$2" alt="$1"/>',
'<a href="$1">$2</a>',
'<abbr title="$1">$2</abbr>',
'<pre class="code">$1</pre>'
);
$str = preg_replace($simple_search,$simple_replace,$str);
return $str;
}