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