$urlReplaceArray = array(
"[url]\\2\\4[/url]"
);
$urlReplaceArray = array(
"[code]\\2\\4[/code]"
);
$text = preg_replace($urlSearchArray, $urlReplaceArray, $messagetext);
$text = str_replace("[/code]\r\n[code]","\r\n",$text);
$text = str_replace("[/code]\n[code]","\n",$text);