fork download
  1. <?php
  2.  
  3. function htmlent2xml($s) {
  4. return preg_replace_callback("/(&[a-zA-Z][a-zA-Z0-9]*;)/",function($m){
  5. $c = html_entity_decode($m[0],ENT_HTML5,"UTF-8");
  6. # return htmlentities($c,ENT_XML1,"UTF-8"); -- see update below
  7.  
  8. $convmap = array(0x80, 0xffff, 0, 0xffff);
  9. return mb_encode_numericentity($c, $convmap, 'UTF-8');
  10. },$s);
  11. }
  12.  
  13. print htmlent2xml("Oggi &egrave; un bel&nbsp;giorno");
Success #stdin #stdout 0.02s 25860KB
stdin
Standard input is empty
stdout
Oggi &#232; un bel&#160;giorno