@ 2014-02-28T16:16:42Z <?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");
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for git.master , git.master_jit , rfc.property-hooks 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 . 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:dark mode live preview
46.71 ms | 401 KiB | 8 Q