输出代码作为php中的文本

Basically, I want to to something similar as to what mybb does in php, where they will output code between [code][/code] tags as highlighted text. Obviously I will need some regular expressions, but what's the key to outputting all php code as plain text, especially after stored in a db.

Edit: not just php code but all code as plain text

IMO, the easiest way would be to:

1) Read your text into a string

2) Optionally, run htmlspecialchars()

3a) echo() the string

3b) be sure to add <pre> and </pre> tags before and after the string