3v4l.org

run code in 300+ PHP versions simultaneously
<?php // PHP < 7.2 // https://github.com/symfony/polyfill-mbstring/blob/master/Mbstring.php#L708-L730 if( ! function_exists("mb_ord") ) { function mb_ord($s) { if (1 === \strlen($s)) { return \ord($s); } $code = ($s = unpack('C*', substr($s, 0, 4))) ? $s[1] : 0; if (0xF0 <= $code) { return (($code - 0xF0) << 18) + (($s[2] - 0x80) << 12) + (($s[3] - 0x80) << 6) + $s[4] - 0x80; } if (0xE0 <= $code) { return (($code - 0xE0) << 12) + (($s[2] - 0x80) << 6) + $s[3] - 0x80; } if (0xC0 <= $code) { return (($code - 0xC0) << 6) + $s[2] - 0x80; } return $code; } } function ord2seqlen($ord) { if($ord < 128){ return 1; } else if($ord < 224) { return 2; } else if($ord < 240) { return 3; } else if($ord < 248) { return 4; } else { throw new \Exception("No support for 5 or 6 byte sequences."); } } function utf8_seq_iter($input) { for($i=0,$c=strlen($input); $i<$c; ) { $bytes = ord2seqlen(ord($input[$i])); yield substr($input, $i, $bytes); $i += $bytes; } } function escape_codepoint($codepoint, $skip_low=true) { $ord = mb_ord($codepoint); if( $skip_low && $ord < 128 ) { return $codepoint; } else { return sprintf("\\u%04x", $ord); } } $input = "आए थे पर्यटक, खुद ही बह गए"; $output = ''; foreach( utf8_seq_iter($input) as $codepoint ) { $output .= escape_codepoint($codepoint); } var_dump($output);
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.27, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
string(121) "\u0906\u090f \u0925\u0947 \u092a\u0930\u094d\u092f\u091f\u0915, \u0916\u0941\u0926 \u0939\u0940 \u092c\u0939 \u0917\u090f"
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 string(121) "\u0906\u090f \u0925\u0947 \u092a\u0930\u094d\u092f\u091f\u0915, \u0916\u0941\u0926 \u0939\u0940 \u092c\u0939 \u0917\u090f"
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected 'substr' (T_STRING) in /in/neN3a on line 41
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/neN3a on line 41
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/neN3a on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/neN3a on line 8 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/neN3a on line 34 Parse error: syntax error, unexpected T_STRING in /in/neN3a on line 41
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/neN3a on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/neN3a on line 8 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/neN3a on line 34 Parse error: parse error, unexpected T_STRING in /in/neN3a on line 41
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/neN3a on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/neN3a on line 8 Parse error: syntax error, unexpected T_NEW in /in/neN3a on line 34
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/neN3a on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/neN3a on line 8 Parse error: parse error, unexpected T_NEW in /in/neN3a on line 34
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/neN3a on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/neN3a on line 8 Parse error: parse error in /in/neN3a on line 34
Process exited with code 255.

preferences:
317.84 ms | 401 KiB | 428 Q