fork download
  1. <?php
  2. header("Content-Type: text/plain; charset=utf-8");
  3.  
  4. function getUtf8Codepoint($char) {
  5. $char = iconv('utf-8', 'utf-32', $char);
  6. $codepoint = '';
  7. if(strlen($char) <> 8){
  8. return false;
  9. }
  10. //utf-32 string starts with 4 bytes BOM and 2 "empty" bytes (FFFE + 0000)
  11. for ($i = strlen($char)-1; $i > 3 ; $i--) {
  12. $codepoint .= sprintf("%02X", ord($char[$i]));
  13. }
  14. $codepoint = preg_replace("/^(0){1,4}/u", "", $codepoint);
  15. return $codepoint;
  16. }
  17.  
  18. $str = "019azAZаяАЯ $ ½ 𢇷𢈋";
  19. echo "String - $str\n";
  20. echo "Codepoints list:\n";
  21.  
  22. $chars = preg_split("//u", $str, null, PREG_SPLIT_NO_EMPTY);
  23.  
  24. foreach ($chars as $char) {
  25. echo "$char\t-\tU+". getUtf8Codepoint($char) . "\n";
  26. }
Success #stdin #stdout 0.01s 52528KB
stdin
Standard input is empty
stdout
String - 019azAZаяАЯ $ ½ 𢇷𢈋
Codepoints list:
0	-	U+0030
1	-	U+0031
9	-	U+0039
a	-	U+0061
z	-	U+007A
A	-	U+0041
Z	-	U+005A
а	-	U+0430
я	-	U+044F
А	-	U+0410
Я	-	U+042F
 	-	U+0020
$	-	U+0024
 	-	U+0020
½	-	U+00BD
 	-	U+0020
𢇷	-	U+221F7
𢈋	-	U+2220B