Is there a PHP function to convert named HTML entities into their respective numeric HTML entities?
For example:
$str = \"Oggi è un bel&am
This one
Here it is
function htmlent2xml($s) {
return preg_replace_callback("/(&[a-zA-Z][a-zA-Z0-9]*;)/",function($m){
$c = html_entity_decode($m[0],ENT_HTML5,"UTF-8");
# return htmlentities($c,ENT_XML1,"UTF-8"); -- see update below
$convmap = array(0x80, 0xffff, 0, 0xffff);
return mb_encode_numericentity($c, $convmap, 'UTF-8');
},$s);
}
upd: Following Carlos's remark, the proposed solution is fixed using this answer to get the required numeric entities.