Location: PHPKode > projects > HB-NS > hb-ns/functions.php
<?php
// file with common functions used in all pages

// this function cleans up the body of the newsitem and replaces bbcode
// it is used in both index.php and newsadmin.php so it is included here
function convertBBCode($text_clean)
{
	// if you don't want to allow html tags uncomment the line below:
	// $text_clean = htmlspecialchars($text_clean);
	// a simple list
	$text_clean = preg_replace("/\[\*\](.*?)\[\/\*\]\r?\n?/si", "<li>\\1</li>", $text_clean);
	$text_clean = preg_replace("/\[list\]\r?\n?(.*?)\[\/list\]\r?\n?/si", "<ul>\\1</ul>", $text_clean);


	$text_clean = nl2br($text_clean);
	$text_clean = preg_replace("/\[b\](.*?)\[\/b\]/si", "<strong>\\1</strong>", $text_clean);
	$text_clean = preg_replace("/\[i\](.*?)\[\/i\]/si", "<em>\\1</em>", $text_clean);
	$text_clean = preg_replace("/\[code\](.*?)\[\/code\]/si", "<code>\\1</code>", $text_clean);
//	$text_clean = preg_replace("/\[pre\](.*?)\[\/pre\]/si", "<pre>\\1</pre>", $text_clean);
	$text_clean = preg_replace("/\[quote\](.*?)\[\/quote\]/si", "<q>\\1</q>", $text_clean);
	$text_clean = preg_replace("#\[email\](.*?)\[/email\]#si",'<a href="mailto:\1">\1</a>',$text_clean);
	$text_clean = preg_replace("#\[img\](.*?)\[/img\]#si",'<img src="\1" border="0" alt=" " />',$text_clean);
	$text_clean = preg_replace("#\[img align=(.*?)\](.*?)\[/img\]#si",'<img src="\2" border="0" alt=" " align="\1" /><div style="clear:both;"></div>',$text_clean);
	$text_clean = preg_replace("#\[abbr\](.*?)\[/abbr\]#si",'<abbr>\1</abbr>',$text_clean);
	$text_clean = preg_replace("#\[abbr=(.*?)\](.*?)\[/abbr\]#si",'<abbr title="\1">\2</abbr>',$text_clean);

	$patterns = array();
	$replacements = array();
	// [0] and [1] are used for url's that are written with the url NOT in the []
	// [2] is for url's that have a protocol (http or ftp or telnet etc.)
	// [3] is for url's without a protocol
	$patterns[0]="#\[url\]([a-z]+?://){1}(.*?)\[/url\]#si";
	$replacements[0]='<a href="\1\2">\1\2</a>';
	$patterns[1] = "#\[url\](.*?)\[/url\]#si";
	$replacements[1] = '<a href="http://\1">\1</a>';
	$patterns[2] = "#\[url=([a-z]+?://){1}(.*?)\](.*?)\[/url\]#si";
	$replacements[2] = '<a href="\1\2">\3</a>';
	$patterns[3] = "#\[url=(.*?)\](.*?)\[/url\]#si";
	$replacements[3] = '<a href="http://\1">\2</a>';

	$text_clean = preg_replace($patterns, $replacements, $text_clean);

	return($text_clean);
}
?>
Return current item: HB-NS