fork download
  1. <?php
  2.  
  3. $str = '&#151;';
  4. function html_dereference($match) {
  5. if (strtolower($match[1][0]) === 'x') {
  6. $codepoint = intval(substr($match[1], 1), 16);
  7. } else {
  8. $codepoint = intval($match[1], 10);
  9. }
  10. return mb_convert_encoding(pack('N', $codepoint), 'UTF-8', 'UTF-32BE');
  11. }
  12. echo $str;
  13. $str = preg_replace_callback('/&#(x[0-9a-f]+|[0-9]+);/i', 'html_dereference', $str);
  14. var_dump($str);
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
&#151;string(2) "—"