3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = '回';echo $str{0};echo urlencode($str); echo $bin = pack("C3", ord($str{0}), ord($str{1}), ord($str{2}));//回 $hex = strtoupper(bin2hex($bin)); echo "UTF-8编码: " . $hex . "\n"; $byte1 = ord($str{0}); $byte2 = ord($str{1}); $byte3 = ord($str{2}); $c1 = (($byte1 & 0x0F) << 4) | (($byte2 & 0x3F) >> 2); $c2 = (($byte2 & 0x03) << 6) | ($byte3 & 0x3F); $dec = (($c1 & 0x00FF) << 8) | $c2; echo "Unicode编码: " . $dec . "\n"; $str = "\u00b6\u00b9\u00c0\u00e0"; $gbk_str = pack("H*", str_replace("\u00", "", $str)); $utf8_str = iconv("GBK", "UTF-8//IGNORE", $gbk_str); $utf8_len = strlen($utf8_str); $res = ""; for ($i = 0; $i < $utf8_len; $i++) { $byte1 = ord($utf8_str{$i}); // UTF-8是变长字节,占1~6字节。 // 这里是固定情况,就不作这么多判断了 // 直接当三字节 if ((($byte1 >> 4) & 0xFF) == 0xE) { // U+00000800 – U+0000FFFF 1110xxxx 10xxxxxx 10xxxxxx $byte2 = ord(substr($utf8_str, ++$i, 1)); $byte3 = ord(substr($utf8_str, ++$i, 1)); $b1 = ($byte1 << 4) | (($byte2 >> 2) & 0x0F); $b2 = (($byte2 & 0x03) << 6) | ($byte3 & 0x3F); $unicode = (($b1 & 0x00FF) << 8) | $b2; $res .= sprintf("\u%x", $unicode); } else { // 略过... } } echo $res . "\n"; // output: \u8c46\u7c7b echo pack("C", 97) . "\n";
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Array and string offset access syntax with curly braces is no longer supported in /in/IHo4t on line 3
Process exited with code 255.
Output for 7.4.33
Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 3 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 4 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 4 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 4 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 7 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 8 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 9 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 21 �%E5%9B%9E回UTF-8编码: E59B9E Unicode编码: 22238 Fatal error: Uncaught Error: Call to undefined function iconv() in /in/IHo4t:16 Stack trace: #0 {main} thrown in /in/IHo4t on line 16
Process exited with code 255.
Output for 7.4.26 - 7.4.32
Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 3 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 4 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 4 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 4 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 7 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 8 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 9 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 21 �%E5%9B%9E回UTF-8编码: E59B9E Unicode编码: 22238 Notice: iconv(): Wrong charset, conversion from `GBK' to `UTF-8//IGNORE' is not allowed in /in/IHo4t on line 16 a
Output for 7.4.0 - 7.4.25
Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 3 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 4 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 4 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 4 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 7 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 8 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 9 Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/IHo4t on line 21 �%E5%9B%9E回UTF-8编码: E59B9E Unicode编码: 22238 \u8c46\u7c7b a
Output for 7.3.32 - 7.3.33
�%E5%9B%9E回UTF-8编码: E59B9E Unicode编码: 22238 Fatal error: Uncaught Error: Call to undefined function iconv() in /in/IHo4t:16 Stack trace: #0 {main} thrown in /in/IHo4t on line 16
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31
�%E5%9B%9E回UTF-8编码: E59B9E Unicode编码: 22238 \u8c46\u7c7b a
Output for 5.4.0 - 5.4.45
�%E5%9B%9E回UTF-8编码: E59B9E Unicode编码: 22238 Fatal error: Call to undefined function iconv() in /in/IHo4t on line 16
Process exited with code 255.
Output for 4.4.5 - 4.4.9
�%E5%9B%9E回UTF-8编码: E59B9E Unicode编码: 22238 Fatal error: Call to undefined function: iconv() in /in/IHo4t on line 16
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
�%E5%9B%9E回UTF-8编码: E59B9E Unicode编码: 22238 Fatal error: Call to undefined function: iconv() in /in/IHo4t on line 16
Process exited with code 255.
Output for 4.3.0 - 4.3.1
�%E5%9B%9E回UTF-8编码: E59B9E Unicode编码: 22238 Fatal error: Call to undefined function: iconv() in /in/IHo4t on line 16

preferences:
344.77 ms | 401 KiB | 465 Q