This is a very old PHP class I wrote for parsing bbCode, a then very popular formatting markup. It is for PHP3, which is very old now.
Feel free to copy, modify or blast it.