fork download
  1. <?php
  2. function uniord($ch)
  3. {
  4.  
  5. $n = ord($ch{0});
  6.  
  7. if ($n < 128) {
  8. return $n; // no conversion required
  9. }
  10.  
  11. if ($n < 192 || $n > 253) {
  12. return false; // bad first byte || out of range
  13. }
  14.  
  15. $arr = array(
  16. 1 => 192, // byte position => range from
  17. 2 => 224,
  18. 3 => 240,
  19. 4 => 248,
  20. 5 => 252
  21. );
  22.  
  23. foreach ($arr as $key => $val) {
  24. if ($n >= $val) { // add byte to the 'char' array
  25. $char[] = ord($ch{$key}) - 128;
  26. $range = $val;
  27. } else {
  28. break; // save some e-trees
  29. }
  30. }
  31.  
  32. $retval = ($n - $range) * pow(64, sizeof($char));
  33.  
  34. foreach ($char as $key => $val) {
  35. $pow = sizeof($char) - ($key + 1); // invert key
  36. $retval += $val * pow(64, $pow); // dark magic
  37. }
  38.  
  39. return $retval;
  40. }
  41. $decimal = '&#' . uniord(json_decode('"\ud83d\ude05"')) . ';';
  42. echo $decimal;
  43. ?>
Success #stdin #stdout 0.01s 82880KB
stdin
Standard input is empty
stdout
&#128517;