3v4l.org

run code in 300+ PHP versions simultaneously
<?php class IDN { // adapt bias for punycode algorithm private static function punyAdapt( $delta, $numpoints, $firsttime ) { $delta = $firsttime ? $delta / 700 : $delta / 2; $delta += $delta / $numpoints; for ($k = 0; $delta > 455; $k += 36) $delta = intval($delta / 35); return $k + (36 * $delta) / ($delta + 38); } // translate character to punycode number private static function decodeDigit($cp) { } // make utf8 string from unicode codepoint number private static function utf8($cp) { if ($cp < 128) return chr($cp); if ($cp < 2048) return chr(192+($cp >> 6)).chr(128+($cp & 63)); if ($cp < 65536) return chr(224+($cp >> 12)). chr(128+(($cp >> 6) & 63)). chr(128+($cp & 63)); if ($cp < 2097152) return chr(240+($cp >> 18)). chr(128+(($cp >> 12) & 63)). chr(128+(($cp >> 6) & 63)). chr(128+($cp & 63)); // it should never get here } // main decoding function private static function decodePart($input) { if (substr($input,0,4) != "xn--") // prefix check... return $input; $input = substr($input,4); // discard prefix $a = explode("-",$input); if (count($a) > 1) { $input = str_split(array_pop($a)); $output = str_split(implode("-",$a)); } else { $output = array(); $input = str_split($input); } $n = 128; $i = 0; $bias = 72; // init punycode vars while (!empty($input)) { $oldi = $i; $w = 1; for ($k = 36;;$k += 36) { $digit = ord(array_shift($input)); if ($digit >= 0x61 && $digit <= 0x7A) { $digit -= 97; } else if ($digit >= 0x30 && $digit <= 0x39) { $digit -= 22; } else { return false; } $i += $digit * $w; if ($k <= $bias) $t = 1; elseif ($k >= $bias + 26) $t = 26; else $t = $k - $bias; if ($digit < $t) break; $w *= intval(36 - $t); } $bias = IDN::punyAdapt( $i-$oldi, count($output)+1, $oldi == 0 ); $n += intval($i / (count($output) + 1)); $i %= count($output) + 1; array_splice($output,$i,0,array(IDN::utf8($n))); $i++; } return implode("",$output); } public static function decodeIDN($name) { // split it, parse it and put it back together return implode( ".", array_map("IDN::decodePart",explode(".",$name)) ); } } echo IDN::decodeIDN("xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n");
Output for 5.2.2 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 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.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
安室奈美恵-with-SUPER-MONKEYS
Output for 5.1.2 - 5.1.6, 5.2.0 - 5.2.1
<br /> <b>Warning</b>: array_map() [<a href='function.array-map'>function.array-map</a>]: An error occurred while invoking the map callback in <b>/in/XX2Ig</b> on line <b>91</b><br /> <br /> <b>Warning</b>: implode() [<a href='function.implode'>function.implode</a>]: Bad arguments. in <b>/in/XX2Ig</b> on line <b>92</b><br />
Output for 5.1.0 - 5.1.1

Process exited with code 139.
Output for 5.0.0 - 5.0.5
<br /> <b>Warning</b>: array_map() [<a href='function.array-map'>function.array-map</a>]: The first argument, 'IDN::decodePart', should be either NULL or a valid callback in <b>/in/XX2Ig</b> on line <b>91</b><br /> <br /> <b>Warning</b>: implode() [<a href='function.implode'>function.implode</a>]: Bad arguments. in <b>/in/XX2Ig</b> on line <b>92</b><br />
Output for 4.4.2 - 4.4.9
<br /> <b>Parse error</b>: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in <b>/in/XX2Ig</b> on line <b>5</b><br />
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
<br /> <b>Parse error</b>: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in <b>/in/XX2Ig</b> on line <b>5</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in <b>/in/XX2Ig</b> on line <b>5</b><br />
Process exited with code 255.

preferences:
255.83 ms | 401 KiB | 371 Q