Replace Special Characters with HTML Codes in PHP

I always struggle to properly convert special characters into HTML when adding to a web page or importing into a database… the foreign characters with accents like Umlauts etc.
Although PHP has a few functions that claim to do it (e.g. htmlentities() ) , it does not work for all characters I have, just some of them.
So I have written a script to do a find and replace on the characters without using PHP built in functions. This allows me to fine control what characters are converted. If I have missed any I can just add them to the list. It would be great to find a complete list of all characters possible so I don’t have to check content all the time for any not included.

$entities = array(
foreach ($entities as $key => $value)
    $ent[] = $key;
    $html_ent[] = $value;
$new_string = str_replace( $ent, $html_ent, $string );