<?
function bbcodehightlight($arr)
{
	$arr[0]=html_entity_decode($arr[0], ENT_QUOTES, 'UTF-8');
	return '<div class="cit" style="overflow:scroll;clip:auto;max-width:480px;">'.preg_replace('#<code>(.*?)</code>#si', '\\1' ,highlight_string($arr[0],1)).'</div>'."\n";
}



function BBcode($msg)
{
	global $set;

	$bbcode=array();$bbcode['/\[br\]/isU']='<br />'; // новая строка

	if ($set['bb_b'])$bbcode['/\[b\](.+)\[\/b\]/isU']='<strong>$1</strong>';
        if ($set['bb_color'])$bbcode['/\[color=#([A-z0-9]+)\](.+)\[\/color\]/isU']='<span style="color:#$1;">$2</span>';
        if ($set['bb_fon'])$bbcode['/\[fon=#([A-z0-9]+)\](.+)\[\/fon\]/isU']='<span style="background:#$1;">$2</span>';
	if ($set['bb_red'])$bbcode['/\[red\](.+)\[\/red\]/isU']='<span style="color:#ff0000;">$1</span>';
        if ($set['bb_cit'])$bbcode['/\[cit\](.+)\[\/cit\]/isU']='<div class="cit">$1</div>';

	if (count($bbcode))$msg= preg_replace(array_keys($bbcode), array_values($bbcode), $msg);

	if ($set['bb_code']){

		$msg=preg_replace_callback('#&lt;\?(.*?)\?&gt;#sui', 'bbcodehightlight', $msg);$msg=preg_replace('#\[code\](.*?)\[/code\]#si', '\1', $msg);

	}

	return $msg;
}
?>