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) { $cp = strtolower($cp); if ($cp >= 'a' && $cp <= 'z') return ord($cp) - ord('a'); elseif ($cp >= '0' && $cp <= '9') return ord($cp) - ord('0')+26; } // 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 = IDN::decodeDigit(array_shift($input)); $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("3B-ww4c5e180e575a65lsy2b");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MRu5H
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   92     0  E >   INIT_STATIC_METHOD_CALL                                  'IDN', 'decodeIDN'
          1        SEND_VAL                                                 '3B-ww4c5e180e575a65lsy2b'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Class IDN:
Function punyadapt:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 14
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 14
Branch analysis from position: 20
Branch analysis from position: 14
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
filename:       /in/MRu5H
function name:  punyAdapt
number of ops:  26
compiled vars:  !0 = $delta, !1 = $numpoints, !2 = $firsttime, !3 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   10     3      > JMPZ                                                     !2, ->7
          4    >   DIV                                              ~4      !0, 700
          5        QM_ASSIGN                                        ~5      ~4
          6      > JMP                                                      ->9
          7    >   DIV                                              ~6      !0, 2
          8        QM_ASSIGN                                        ~5      ~6
          9    >   ASSIGN                                                   !0, ~5
   11    10        DIV                                              ~8      !0, !1
         11        ASSIGN_OP                                     1          !0, ~8
   12    12        ASSIGN                                                   !3, 0
         13      > JMP                                                      ->18
   13    14    >   DIV                                              ~11     !0, 35
         15        CAST                                          4  ~12     ~11
         16        ASSIGN                                                   !0, ~12
   12    17        ASSIGN_OP                                     1          !3, 36
         18    >   IS_SMALLER                                               455, !0
         19      > JMPNZ                                                    ~15, ->14
   14    20    >   MUL                                              ~16     !0, 36
         21        ADD                                              ~17     !0, 38
         22        DIV                                              ~18     ~16, ~17
         23        ADD                                              ~19     !3, ~18
         24      > RETURN                                                   ~19
   15    25*     > RETURN                                                   null

End of function punyadapt

Function decodedigit:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 27
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 9
filename:       /in/MRu5H
function name:  decodeDigit
number of ops:  28
compiled vars:  !0 = $cp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        INIT_FCALL                                               'strtolower'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
   20     5        IS_SMALLER_OR_EQUAL                              ~3      'a', !0
          6      > JMPZ_EX                                          ~3      ~3, ->9
          7    >   IS_SMALLER_OR_EQUAL                              ~4      !0, 'z'
          8        BOOL                                             ~3      ~4
          9    > > JMPZ                                                     ~3, ->16
   21    10    >   INIT_FCALL                                               'ord'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $5      
         13        SUB                                              ~6      $5, 97
         14      > RETURN                                                   ~6
         15*       JMP                                                      ->27
   22    16    >   IS_SMALLER_OR_EQUAL                              ~7      '0', !0
         17      > JMPZ_EX                                          ~7      ~7, ->20
         18    >   IS_SMALLER_OR_EQUAL                              ~8      !0, '9'
         19        BOOL                                             ~7      ~8
         20    > > JMPZ                                                     ~7, ->27
   23    21    >   INIT_FCALL                                               'ord'
         22        SEND_VAR                                                 !0
         23        DO_ICALL                                         $9      
         24        SUB                                              ~10     $9, 48
         25        ADD                                              ~11     ~10, 26
         26      > RETURN                                                   ~11
   24    27    > > RETURN                                                   null

End of function decodedigit

Function utf8:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 21
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 42
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 70
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 70
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MRu5H
function name:  utf8
number of ops:  71
compiled vars:  !0 = $cp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        IS_SMALLER                                               !0, 128
          2      > JMPZ                                                     ~1, ->7
          3    >   INIT_FCALL                                               'chr'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6      > RETURN                                                   $2
   29     7    >   IS_SMALLER                                               !0, 2048
          8      > JMPZ                                                     ~3, ->21
   30     9    >   INIT_FCALL                                               'chr'
         10        SR                                               ~4      !0, 6
         11        ADD                                              ~5      192, ~4
         12        SEND_VAL                                                 ~5
         13        DO_ICALL                                         $6      
         14        INIT_FCALL                                               'chr'
         15        BW_AND                                           ~7      !0, 63
         16        ADD                                              ~8      128, ~7
         17        SEND_VAL                                                 ~8
         18        DO_ICALL                                         $9      
         19        CONCAT                                           ~10     $6, $9
         20      > RETURN                                                   ~10
   31    21    >   IS_SMALLER                                               !0, 65536
         22      > JMPZ                                                     ~11, ->42
   32    23    >   INIT_FCALL                                               'chr'
         24        SR                                               ~12     !0, 12
         25        ADD                                              ~13     224, ~12
         26        SEND_VAL                                                 ~13
         27        DO_ICALL                                         $14     
   33    28        INIT_FCALL                                               'chr'
         29        SR                                               ~15     !0, 6
         30        BW_AND                                           ~16     ~15, 63
         31        ADD                                              ~17     128, ~16
         32        SEND_VAL                                                 ~17
         33        DO_ICALL                                         $18     
         34        CONCAT                                           ~19     $14, $18
   34    35        INIT_FCALL                                               'chr'
         36        BW_AND                                           ~20     !0, 63
         37        ADD                                              ~21     128, ~20
         38        SEND_VAL                                                 ~21
         39        DO_ICALL                                         $22     
         40        CONCAT                                           ~23     ~19, $22
         41      > RETURN                                                   ~23
   35    42    >   IS_SMALLER                                               !0, 2097152
         43      > JMPZ                                                     ~24, ->70
   36    44    >   INIT_FCALL                                               'chr'
         45        SR                                               ~25     !0, 18
         46        ADD                                              ~26     240, ~25
         47        SEND_VAL                                                 ~26
         48        DO_ICALL                                         $27     
   37    49        INIT_FCALL                                               'chr'
         50        SR                                               ~28     !0, 12
         51        BW_AND                                           ~29     ~28, 63
         52        ADD                                              ~30     128, ~29
         53        SEND_VAL                                                 ~30
         54        DO_ICALL                                         $31     
         55        CONCAT                                           ~32     $27, $31
   38    56        INIT_FCALL                                               'chr'
         57        SR                                               ~33     !0, 6
         58        BW_AND                                           ~34     ~33, 63
         59        ADD                                              ~35     128, ~34
         60        SEND_VAL                                                 ~35
         61        DO_ICALL                                         $36     
         62        CONCAT                                           ~37     ~32, $36
   39    63        INIT_FCALL                                               'chr'
         64        BW_AND                                           ~38     !0, 63
         65        ADD                                              ~39     128, ~38
         66        SEND_VAL                                                 ~39
         67        DO_ICALL                                         $40     
         68        CONCAT                                           ~41     ~37, $40
         69      > RETURN                                                   ~41
   41    70    > > RETURN                                                   null

End of function utf8

Function decodepart:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 38
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 108
Branch analysis from position: 108
2 jumps found. (Code = 44) Position 1 = 111, Position 2 = 47
Branch analysis from position: 111
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
2 jumps found. (Code = 44) Position 1 = 79, Position 2 = 51
Branch analysis from position: 79
2 jumps found. (Code = 44) Position 1 = 111, Position 2 = 47
Branch analysis from position: 111
Branch analysis from position: 47
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 64
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 74
Branch analysis from position: 73
1 jumps found. (Code = 42) Position 1 = 79
Branch analysis from position: 79
Branch analysis from position: 74
2 jumps found. (Code = 44) Position 1 = 79, Position 2 = 51
Branch analysis from position: 79
Branch analysis from position: 51
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 69
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
Branch analysis from position: 69
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 74
Branch analysis from position: 73
Branch analysis from position: 74
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 108
Branch analysis from position: 108
filename:       /in/MRu5H
function name:  decodePart
number of ops:  117
compiled vars:  !0 = $input, !1 = $a, !2 = $output, !3 = $n, !4 = $i, !5 = $bias, !6 = $oldi, !7 = $w, !8 = $k, !9 = $digit, !10 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
   45     1        INIT_FCALL                                               'substr'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 4
          5        DO_ICALL                                         $11     
          6        IS_NOT_EQUAL                                             $11, 'xn--'
          7      > JMPZ                                                     ~12, ->9
   46     8    > > RETURN                                                   !0
   47     9    >   INIT_FCALL                                               'substr'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 4
         12        DO_ICALL                                         $13     
         13        ASSIGN                                                   !0, $13
   48    14        INIT_FCALL                                               'explode'
         15        SEND_VAL                                                 '-'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $15     
         18        ASSIGN                                                   !1, $15
   49    19        COUNT                                            ~17     !1
         20        IS_SMALLER                                               1, ~17
         21      > JMPZ                                                     ~18, ->38
   50    22    >   INIT_FCALL                                               'str_split'
         23        INIT_FCALL                                               'array_pop'
         24        SEND_REF                                                 !1
         25        DO_ICALL                                         $19     
         26        SEND_VAR                                                 $19
         27        DO_ICALL                                         $20     
         28        ASSIGN                                                   !0, $20
   51    29        INIT_FCALL                                               'str_split'
         30        INIT_FCALL                                               'implode'
         31        SEND_VAL                                                 '-'
         32        SEND_VAR                                                 !1
         33        DO_ICALL                                         $22     
         34        SEND_VAR                                                 $22
         35        DO_ICALL                                         $23     
         36        ASSIGN                                                   !2, $23
         37      > JMP                                                      ->43
   53    38    >   ASSIGN                                                   !2, <array>
   54    39        INIT_FCALL                                               'str_split'
         40        SEND_VAR                                                 !0
         41        DO_ICALL                                         $26     
         42        ASSIGN                                                   !0, $26
   56    43    >   ASSIGN                                                   !3, 128
         44        ASSIGN                                                   !4, 0
         45        ASSIGN                                                   !5, 72
   57    46      > JMP                                                      ->108
   58    47    >   ASSIGN                                                   !6, !4
   59    48        ASSIGN                                                   !7, 1
   60    49        ASSIGN                                                   !8, 36
         50      > JMP                                                      ->78
   61    51    >   INIT_STATIC_METHOD_CALL                                  'IDN', 'decodeDigit'
         52        INIT_FCALL                                               'array_shift'
         53        SEND_REF                                                 !0
         54        DO_ICALL                                         $34     
         55        SEND_VAR                                                 $34
         56        DO_FCALL                                      0  $35     
         57        ASSIGN                                                   !9, $35
   62    58        MUL                                              ~37     !9, !7
         59        ASSIGN_OP                                     1          !4, ~37
   63    60        IS_SMALLER_OR_EQUAL                                      !8, !5
         61      > JMPZ                                                     ~39, ->64
         62    >   ASSIGN                                                   !10, 1
         63      > JMP                                                      ->71
   64    64    >   ADD                                              ~41     !5, 26
         65        IS_SMALLER_OR_EQUAL                                      ~41, !8
         66      > JMPZ                                                     ~42, ->69
         67    >   ASSIGN                                                   !10, 26
         68      > JMP                                                      ->71
   65    69    >   SUB                                              ~44     !8, !5
         70        ASSIGN                                                   !10, ~44
   66    71    >   IS_SMALLER                                               !9, !10
         72      > JMPZ                                                     ~46, ->74
         73    > > JMP                                                      ->79
   67    74    >   SUB                                              ~47     36, !10
         75        CAST                                          4  ~48     ~47
         76        ASSIGN_OP                                     3          !7, ~48
   60    77        ASSIGN_OP                                     1          !8, 36
         78    > > JMPNZ                                                    <true>, ->51
   69    79    >   INIT_STATIC_METHOD_CALL                                  'IDN', 'punyAdapt'
   70    80        SUB                                              ~51     !4, !6
         81        SEND_VAL                                                 ~51
   71    82        COUNT                                            ~52     !2
         83        ADD                                              ~53     ~52, 1
         84        SEND_VAL                                                 ~53
   72    85        IS_EQUAL                                         ~54     !6, 0
         86        SEND_VAL                                                 ~54
         87        DO_FCALL                                      0  $55     
   69    88        ASSIGN                                                   !5, $55
   74    89        COUNT                                            ~57     !2
         90        ADD                                              ~58     ~57, 1
         91        DIV                                              ~59     !4, ~58
         92        CAST                                          4  ~60     ~59
         93        ASSIGN_OP                                     1          !3, ~60
   75    94        COUNT                                            ~62     !2
         95        ADD                                              ~63     ~62, 1
         96        ASSIGN_OP                                     5          !4, ~63
   76    97        INIT_FCALL                                               'array_splice'
         98        SEND_REF                                                 !2
         99        SEND_VAR                                                 !4
        100        SEND_VAL                                                 0
        101        INIT_STATIC_METHOD_CALL                                  'IDN', 'utf8'
        102        SEND_VAR                                                 !3
        103        DO_FCALL                                      0  $65     
        104        INIT_ARRAY                                       ~66     $65
        105        SEND_VAL                                                 ~66
        106        DO_ICALL                                                 
   77   107        PRE_INC                                                  !4
   57   108    >   ISSET_ISEMPTY_CV                                 ~69     !0
        109        BOOL_NOT                                         ~70     ~69
        110      > JMPNZ                                                    ~70, ->47
   79   111    >   INIT_FCALL                                               'implode'
        112        SEND_VAL                                                 ''
        113        SEND_VAR                                                 !2
        114        DO_ICALL                                         $71     
        115      > RETURN                                                   $71
   80   116*     > RETURN                                                   null

End of function decodepart

Function decodeidn:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MRu5H
function name:  decodeIDN
number of ops:  15
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E >   RECV                                             !0      
   85     1        INIT_FCALL                                               'implode'
   86     2        SEND_VAL                                                 '.'
   87     3        INIT_FCALL                                               'array_map'
          4        SEND_VAL                                                 'IDN%3A%3AdecodePart'
          5        INIT_FCALL                                               'explode'
          6        SEND_VAL                                                 '.'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $1      
          9        SEND_VAR                                                 $1
         10        DO_ICALL                                         $2      
         11        SEND_VAR                                                 $2
         12        DO_ICALL                                         $3      
         13      > RETURN                                                   $3
   89    14*     > RETURN                                                   null

End of function decodeidn

End of class IDN.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
283.23 ms | 1420 KiB | 36 Q