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