Hi, I'm currently working on a CMS and I'm doing the BBCode functions for it at the moment. Actually, I've been doing one part of the function for the last three days, and it has been driving me slowly but surely mental. Whatever I do, I [b]CANNOT[/b] get this to work. I'll post the code I'm currently using, then try to explain my problem: [code]<? function highlight($txt="") { $txt = html_entity_decode($txt, ENT_QUOTES); $txt = "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\"><tr><td class=\"code\"><div class=\"title\">Code</div><div class=\"content\">".highlight_string($txt, true)."</div></td></tr></table>"; return $txt; } function bbcode($message) { $message = preg_replace("'\n'", "<br>", $message); $message = preg_replace("'\[b\](.*?)\[/b\]'", "<b>$1</b>", $message); $message = preg_replace("'\[i\](.*?)\[/i\]'", "<i>$1</i>", $message); $message = preg_replace("'\[u\](.*?)\[/u\]'", "<u>$1</u>", $message); $message = preg_replace("'\[code\](.*?)\[/code\]'", highlight('$1'), $message); return $message; } ?>[/code] That's my function.php file, which is included in every single page. Anyway, it is the code tags ([*code][*/code] - without the asterisks) that I am having problems with. I've tried various ways of doing this, and so far none of them have worked. This is the one I have got at the moment, and it is the closest I have gotten to a working function. Anyway, the problem is that when the posted message is shown, it either shows '$1' instead of the text between the code tags, or it shows the text between the code tags, but not highlighted. The thing that is driving me to insanity is that even if the message put through the function is the same, it comes out differently at the end. For example, I might enter [*code]<? phpinfo(); ?>[*/code] once, and it will display '$1' (without the quotes), then if I enter the [b]exact[/b] same message, it might display '<? phpinfo(); ?>', but not highlighted at all. I really have no idea what is wrong with it now, so any help at all that anyone can offer would be amazing. Thanks so much.