Well, first off, all these buttons [on the composition page] are written in Javascript, not PHP (otherwise they wouldn't be able to work in your browser). You've probably got the code in your browser cache (judging from this page's source it goes by the name vbcode.js)
All they do is insert some fake HTML-like markup tags into the text field. The ones used in this forum use just the same as the HTML ones (<b>, <i>, <u>) except they use square brackets instead of angled ones.
Then the forum software goes through the submitted text and replaces square-bracketed b, i, and u tags with angle-bracketed ones. And that completes the embolding, italicising, and underlining of the indicated pieces of the text.
I think you'll find several examples of this sort of thing in the code snippets section. My first cut at text-formatting code (based on square-bracketed pseudo-HTML) would go:
$textfield = htmlspecialchars($textfield);
$textfield = preg_replace("#\[(/?)([biu])\]#i", "<\\1\\2>", $textfield);
Which doesn't check for things like all tags being closed or properly nested. That requires a bit more work.
The advantage is of course that the forum builders can design their own markup as they see fit. The disadvantage is that the back end has to do that conversion. An alternative would be to use HTML tags and use the strip_tags() function to remove all but those tags you want to allow (<b>, <i>, <u>, etc.). But that has drawbacks of its own, as documented in the manual.