PHP: Convertire tutti i possibili caratteri in entità HTML

Per convertire tutti i possibili caratteri nelle rispettive entità HTML si può usare la funzione htmlentities.
<?php
$testo
="Quel che sarĂ , sarĂ ";
echo 
htmlentities($testo); // Quel che sar&agrave;, sar&agrave;
?>


Invece, se si vogliono utilizzare le entità numeriche, si può utilizzare questa funzione:
<?php
function htmlnumericentities($testo){
    return 
preg_replace(\'/[^!-%x27-;=?-~ ]/e\',\'"&#".ord("$0").chr(59)\',$testo);
}
?>