Please note: This does not convert all HTML tags, only the simple ones.
';
/*
Performes BBCode conversion for some simple HTML elements
@staticvar string $str_http_valid
@staticvar array $arr_replace
@param string $string
@return string
@since Mon Mar 06 23:44:40 CST 2006
@author rsalazar
*/
function to_bbcode($string) {
static $str_http_valid = '-:\/a-z.0-9_%+';
$arr_replace = array(
"/(.+?)<\/a>/Xis"
=> '[url=\\2\\3]\\4[/url]',
"/
/Xis"
=> '[img]\\2\\3[/img]',
'/<(\/)?(strong|em)>/Xise' => '( strcasecmp("em", "\\2") ?
"[\\1b]" : "[\\1i]" )',
'/<(\/?(?:b|i|u))>/Xis' => '[\\1]',
'/<(\/)?[ou]l>/Xis' => '[\\1list]',
'/<(\/)?li>/Xise' => '( "\\1" == "" ? "[*]" : "" )',
);
$string = preg_replace(array_keys($arr_replace),
array_values($arr_replace),
$string);
return $string;
}
$text = to_bbcode($text);
echo '';
?>