3v4l.org

run code in 300+ PHP versions simultaneously
<?php class IDN { private function adaptBias($delta, $numpoints, $first) { $delta = $first ? $delta / 700 : $delta / 2; $delta += $delta / $numPoints; for ($k = 0; $delta > 455; $k += 36) { $delta = (int)($delta / 35); } return $k + (36 * $delta) / ($delta + 38); } private function encodeUtf8CodePoint($codePoint) { switch (true) { case $codePoint < 0x80: return pack('C*', $codePoint & 0x7F); case $codePoint < 0x0800: return pack('C*', (($codePoint & 0x07C0) >> 6) | 0xC0, ($codePoint & 0x3F) | 0x80); case $codePoint < 0x010000: return pack('C*', (($codePoint & 0xF000) >> 12) | 0xE0, (($codePoint & 0x0FC0) >> 6) | 0x80, ($codePoint & 0x3F) | 0x80); case $codePoint < 0x110000: return pack('C*', (($codePoint & 0x1C0000) >> 18) | 0xF0, (($codePoint & 0x03F000) >> 12) | 0x80, (($codePoint & 0x0FC0) >> 6) | 0x80, ($codePoint & 0x3F) | 0x80); } return false; } public function decodePart($input) { if (substr($input, 0, 4) !== 'xn--') { return $input; } $input = substr($input, 4); if (false !== $nonBasicCharsStart = strrpos($input, '-')) { $output = str_split(substr($input, 0, $nonBasicCharsStart), 1); $nonBasicChars = substr($input, $nonBasicCharsStart + 1); } else { $output = []; $nonBasicChars = $input; } $n = 128; $i = 0; $bias = 72; for ($j = 0, $l = strlen($nonBasicChars); $j < $l; $i++) { $oldi = $i; $w = 1; $k = 36; while (true) { if (!isset($nonBasicChars[$j])) { return false; } $digit = ord($nonBasicChars[$j++]); 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; } else if ($k >= $bias + 26) { $t = 26; } else { $t = $k - $bias; } if ($digit < $t) { break; } $w *= (int) (36 - $t); $k += 36; } $c = count($output) + 1; $bias = $this->adaptBias($i - $oldi, $c, $oldi === 0); $n += (int)($i / $c); $i %= $c; array_splice($output, $i, 0, array($this->encodeUtf8CodePoint($n))); } return implode('', $output); } public function decodeIDN($name) { // split it, parse it and put it back together return implode( ".", array_map([$this, 'decodePart'],explode(".",$name)) ); } } echo (new IDN)->decodeIDN("xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n");
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Warning: Undefined variable $numPoints in /in/3sguX on line 7 Fatal error: Uncaught DivisionByZeroError: Division by zero in /in/3sguX:7 Stack trace: #0 /in/3sguX(93): IDN->adaptBias(649.37142857143, 20, true) #1 [internal function]: IDN->decodePart('-with-SUPER-MON...') #2 /in/3sguX(108): array_map(Array, Array) #3 /in/3sguX(114): IDN->decodeIDN('xn---with-SUPER...') #4 {main} thrown in /in/3sguX on line 7
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined variable: numPoints in /in/3sguX on line 7 Warning: Division by zero in /in/3sguX on line 7 Notice: Undefined variable: numPoints in /in/3sguX on line 7 Warning: Division by zero in /in/3sguX on line 7 Notice: Undefined variable: numPoints in /in/3sguX on line 7 Warning: Division by zero in /in/3sguX on line 7 Notice: Undefined variable: numPoints in /in/3sguX on line 7 Warning: Division by zero in /in/3sguX on line 7
Output for 7.3.32 - 7.3.33
Warning: Division by zero in /in/3sguX on line 7 Warning: Division by zero in /in/3sguX on line 7 Warning: Division by zero in /in/3sguX on line 7 Warning: Division by zero in /in/3sguX on line 7
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Notice: Undefined variable: numPoints in /in/3sguX on line 7 Warning: Division by zero in /in/3sguX on line 7 Notice: Undefined variable: numPoints in /in/3sguX on line 7 Warning: Division by zero in /in/3sguX on line 7 Notice: Undefined variable: numPoints in /in/3sguX on line 7 Warning: Division by zero in /in/3sguX on line 7 Notice: Undefined variable: numPoints in /in/3sguX on line 7 Warning: Division by zero in /in/3sguX on line 7 Notice: Undefined variable: numPoints in /in/3sguX on line 7 Warning: Division by zero in /in/3sguX on line 7 奈-wit怣h-SUPER-繋M孝學ONKEYS
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/3sguX on line 45
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/3sguX on line 45
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/3sguX on line 4
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
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/3sguX on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/3sguX on line 4
Process exited with code 255.

preferences:
298.07 ms | 401 KiB | 456 Q