Doesn't PHP have tons of classes and modules already doing this stuff? I know that Perl has and I simply can't imagine PHP doesn't.
If you REALLY want to do this all by yourself, grab the iso-8859-1 value of the char and wrap it into &#thevalue;. In this lower byte ranges, the iso-8859-1 value is identical to the Unicode code point - just add leading zeros.
Meaning: What is (hex) C4 in man iso-8859-1 (Ä) is 00C4 in Unicode and &#x C4; in HTML. (Spaces for visualization here - remove.)
See this handy table:
http://en.wikipedia.org/wiki/List_of...ity_references
and check man iso-8859-1 and man unicode.
A simple dispatch table will also do the trick.