3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = '🇷🇴'; echo '=== UTF-8 =============================', PHP_EOL; echo 'STRING: ', $string, PHP_EOL; echo 'CHARACTERS: ', mb_strlen($string), PHP_EOL; // 2 echo 'BYTE COUNT: ', mb_strlen($string, '8bit'), PHP_EOL; // 8 foreach(range(0, mb_strlen($string) - 1) as $index) { echo PHP_EOL; echo 'CHARACTER #', $index + 1, ' CODE POINT: ', '0x', dechex(mb_ord(mb_substr($string, $index, 1))), PHP_EOL; // [0x1f1f7, 0x1f1f4] echo 'CHARACTER #', $index + 1, ' BYTE COUNT: ', mb_strlen(mb_substr($string, $index, 1), '8bit'), PHP_EOL; // [4, 4] } echo '=======================================', PHP_EOL, PHP_EOL; $string = mb_convert_encoding($string, 'UTF-16', 'UTF-8'); echo '=== UTF-16 ============================', PHP_EOL; echo 'STRING: ', $string, PHP_EOL; echo 'CHARACTERS: ', mb_strlen($string), PHP_EOL; // should be 2, is 4 echo 'BYTE COUNT: ', strlen($string), PHP_EOL; // should be 8, is 8 foreach(range(0, mb_strlen($string) - 1) as $index) { echo PHP_EOL; echo 'CHARACTER #', $index + 1, ' CODE POINT: ', '0x', dechex(mb_ord(mb_substr($string, $index, 1))), PHP_EOL; // should be [0x1f1f7, 0x1f1f4], is [0x0, 0x0, 0x0, 0x0] echo 'CHARACTER #', $index + 1, ' BYTE COUNT: ', mb_strlen(mb_substr($string, $index, 1), '8bit'), PHP_EOL; // should be [4, 4], is [2, 2, 2, 2] } echo '=======================================', PHP_EOL;
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 8.0.0 - 8.0.12, 8.1rc1 - rc3
=== UTF-8 ============================= STRING: 🇷🇴 CHARACTERS: 2 BYTE COUNT: 8 CHARACTER #1 CODE POINT: 0x1f1f7 CHARACTER #1 BYTE COUNT: 4 CHARACTER #2 CODE POINT: 0x1f1f4 CHARACTER #2 BYTE COUNT: 4 ======================================= === UTF-16 ============================ STRING: �<��<�� CHARACTERS: 4 BYTE COUNT: 8 CHARACTER #1 CODE POINT: 0x0 CHARACTER #1 BYTE COUNT: 2 CHARACTER #2 CODE POINT: 0x0 CHARACTER #2 BYTE COUNT: 2 CHARACTER #3 CODE POINT: 0x0 CHARACTER #3 BYTE COUNT: 2 CHARACTER #4 CODE POINT: 0x0 CHARACTER #4 BYTE COUNT: 2 =======================================

preferences:
102.15 ms | 539 KiB | 18 Q