// BB CODE PARSER FOR boastMachine
function BBCode($text=null) {
if(!trim($text)) { return; }
// Set up the parameters for a URL search string
$URLSearchString = "\r\n a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'";
// Set up the parameters for a MAIL search string
$MAILSearchString = $URLSearchString . " a-zA-Z0-9\.@";
// Perform URL Search
$text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/is", '$1', $text);
$text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])is", '$2', $text);
$text = preg_replace("/\[a\]([$URLSearchString]*)\[\/a\]/is", '$1', $text);
$text = preg_replace("(\[a\=([$URLSearchString]*)\](.+?)\[/a\])is", '$2', $text);
// Perform MAIL Search
$text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])is", '$1', $text);
$text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.+?)\[\/mail\]/is", '$2', $text);
$text = preg_replace("/\[b\](.+?)\[\/b\]/is", '$1', $text);
// Check for Italics $text
$text = str_replace("[i]","",$text);
$text = str_replace("[I]","",$text);
$text = str_replace("[/i]","",$text);
$text = str_replace("[/I]","",$text);
// Check for Underline $text
$text = str_replace("[u]","",$text);
$text = str_replace("[U]","",$text);
$text = str_replace("[/u]","",$text);
$text = str_replace("[/U]","",$text);
// Check for strike-through $text
$text = str_replace("[s]","",$text);
$text = str_replace("[S]","",$text);
$text = str_replace("[/s]","",$text);
$text = str_replace("[/S]","",$text);
// Check for colored $text
$text = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is","$2",$text);
// Check for sized $text
$text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is","$2",$text);
// Check for font change $text
$text = preg_replace("(\[font=(.+?)\](.+?)\[\/font\])is","$2",$text);
// Check for [code] $text
$text = preg_replace("/\[code\](.+?)\[\/code\]/is","
$1
", $text);
// Declare the format for [quote] layout
$text = preg_replace("/\[quote\](.+?)\[\/quote\]/is","$1
", $text);
// Images
// [img]pathtoimage[/img]
$text = preg_replace("/\[img\](.+?)\[\/img\]/is", '', $text);
// [img=width * height]image source[/img]
// eg: [img=420*60]http://ite.com/a.gif[/img]
$text = preg_replace("/\[img\=([0-9]*)\*([0-9]*)\](.+?)\[\/img\]/is", '', $text);
// Multimedia for mp3
// eq: [mp3]http://michu/michu.mp3[/mp3]
$text = preg_replace("/\[mp3\](.+?)\[\/mp3\]/is", '', $text);
// Multimedia for mp3 - autostart is false
// eq: [mp3=false]http://michu/michu.mp3[/mp3]
$text = preg_replace("/\[mp3=(.+?)\](.+?)\[\/mp3\]/is", '', $text);
// [IMG_L][/IMG_L]
$text = preg_replace("/\[img_l\](.+?)\[\/img_l\]/is", '', $text);
// [IMG_R][/IMG_R]
$text = preg_replace("/\[img_r\](.+?)\[\/img_r\]/is", '', $text);
// [pre] and [/pre] for predefined text.
//$text = preg_replace("#\[pre\](.*?)\[/pre\]#sie", 'stripslashes(str_replace("\n", "", "\\1
"))', $text);
//$text = preg_replace("/\[pre\](.+?)\[\/pre\]/is","\\1
", $text);
$text = preg_replace("/\[pre\](.+?)\[\/pre\]/is",'$1
', $text);
$text = preg_replace("/\[h1\](.+?)\[\/h1\]/is",'$1
', $text);
$text = preg_replace("/\[h2\](.+?)\[\/h2\]/is","$1
", $text);
$text = preg_replace("/\[h3\](.+?)\[\/h3\]/is","$1
", $text);
$text = preg_replace("/\[h4\](.+?)\[\/h4\]/is","$1
", $text);
$text = preg_replace("/\[h5\](.+?)\[\/h5\]/is","$1
", $text);
$text = preg_replace("/\[h6\](.+?)\[\/h6\]/is","$1
", $text);
$text = preg_replace("/\[tt\](.+?)\[\/tt\]/is","\\1", $text);
$text = preg_replace("/\[list\](.+?)\[\/list\]/is","", $text);
$text = preg_replace("/\[li\](.+?)\[\/li\]/is","\\1", $text);
$text = preg_replace("/\[ol\](.+?)\[\/ol\]/is","\\1
", $text);
$text = preg_replace("/\[list=1\](.+?)\[\/list\]/is","\\1
", $text);
$text = preg_replace("/\[list=a\](.+?)\[\/list\]/is","\\1
", $text);
$text = preg_replace("/\[list=I\](.+?)\[\/list\]/is","\\1
", $text);
$text = preg_replace("/\[list=A\](.+?)\[\/list\]/is","\\1
", $text);
//$text = str_replace('[list]', '', $text);
//$text = str_replace('[list=1]', '', $text);
//$text = str_replace('[list=a]', '', $text);
//$text = str_replace('[list=A]', '', $text);
//$text = str_replace('[list=I]', '', $text);
//$text = str_replace('[*]', '- ', $text);
//$text = str_replace('[/list]', '
', $text);
$text = preg_replace("/\[sup\](.+?)\[\/sup\]/is","\\1", $text);
$text = preg_replace("/\[sub\](.+?)\[\/sub\]/is","\\1", $text);
$text = preg_replace("/\[move\](.+?)\[\/move\]/is","", $text);
$text = preg_replace("/\[bgcolor=(.+?)\](.+?)\[\/bgcolor\]/is","\\2", $text);
$text = preg_replace("/\[sig\](.+?)\[\/sig\]/is","
--------------------------
\\1
--------------------------
", $text);
$text = eregi_replace("\\[flash=([^\\[]*)\\,([^\\[]*)\\]([^\\[]*)\\[/flash\\]","", $text);
$text = eregi_replace("\\[align=([^\\[]*)\\]([^\\[]*)\\[/align\\]","\\2
", $text);
$text = eregi_replace("\\[shadow=([^\\[]*)\\,([^\\[]*)\\,([^\\[]*)\\]([^\\[]*)\\[/shadow\\]","\\4", $text);
$text = eregi_replace("\\[glow=([^\\[]*)\\,([^\\[]*)\\,([^\\[]*)\\]([^\\[]*)\\[/glow\\]","\\4", $text);
$text = preg_replace("/\[center\](.+?)\[\/center\]/is","\\2", $text);
$text = preg_replace("/\[justify\](.+?)\[\/justify\]/is","
\\2
", $text);
$text = preg_replace("/\[left\](.+?)\[\/left\]/is","\\2
", $text);
$text = preg_replace("/\[right\](.+?)\[\/right\]/is","\\2
", $text);
return $text;
}