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 git.master, git.master_jit, rfc.property-hooks
string(121) "\u0906\u090f \u0925\u0947 \u092a\u0930\u094d\u092f\u091f\u0915, \u0916\u0941\u0926 \u0939\u0940 \u092c\u0939 \u0917\u090f"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
70.74 ms | 401 KiB | 8 Q