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); } // 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--') { return $input; } $input = substr($input, 4); if (false !== $nonBasicCharsStart = strrpos($input, '-')) { $nonBasicChars = str_split(substr($input, $nonBasicCharsStart + 1), 1); $output = str_split(substr($input, 0, $nonBasicCharsStart), 1); } else { $nonBasicChars = str_split($input, 1); $output = []; } $n = 128; $i = 0; $bias = 72; // init punycode vars while (!empty($input)) { $oldi = $i; $w = 1; for ($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; } else if ($k >= $bias + 26) { $t = 26; } else { $t = $k - $bias; } if ($digit < $t) { break; } $w *= (int) (36 - $t); $k += 36; } $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");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/59ZXb
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  105     0  E >   INIT_STATIC_METHOD_CALL                                  'IDN', 'decodeIDN'
          1        SEND_VAL                                                 'xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n'
          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/59ZXb
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 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/59ZXb
function name:  utf8
number of ops:  71
compiled vars:  !0 = $cp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        IS_SMALLER                                               !0, 128
          2      > JMPZ                                                     ~1, ->7
          3    >   INIT_FCALL                                               'chr'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6      > RETURN                                                   $2
   20     7    >   IS_SMALLER                                               !0, 2048
          8      > JMPZ                                                     ~3, ->21
   21     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
   22    21    >   IS_SMALLER                                               !0, 65536
         22      > JMPZ                                                     ~11, ->42
   23    23    >   INIT_FCALL                                               'chr'
         24        SR                                               ~12     !0, 12
         25        ADD                                              ~13     224, ~12
         26        SEND_VAL                                                 ~13
         27        DO_ICALL                                         $14     
   24    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
   25    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
   26    42    >   IS_SMALLER                                               !0, 2097152
         43      > JMPZ                                                     ~24, ->70
   27    44    >   INIT_FCALL                                               'chr'
         45        SR                                               ~25     !0, 18
         46        ADD                                              ~26     240, ~25
         47        SEND_VAL                                                 ~26
         48        DO_ICALL                                         $27     
   28    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
   29    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
   30    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
   32    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 = 21, Position 2 = 42
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 128
Branch analysis from position: 128
2 jumps found. (Code = 44) Position 1 = 131, Position 2 = 52
Branch analysis from position: 131
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 98
Branch analysis from position: 98
2 jumps found. (Code = 44) Position 1 = 99, Position 2 = 56
Branch analysis from position: 99
2 jumps found. (Code = 44) Position 1 = 131, Position 2 = 52
Branch analysis from position: 131
Branch analysis from position: 52
Branch analysis from position: 56
2 jumps found. (Code = 46) Position 1 = 65, Position 2 = 67
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 70
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 84
Branch analysis from position: 82
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
2 jumps found. (Code = 43) Position 1 = 93, Position 2 = 94
Branch analysis from position: 93
1 jumps found. (Code = 42) Position 1 = 99
Branch analysis from position: 99
Branch analysis from position: 94
2 jumps found. (Code = 44) Position 1 = 99, Position 2 = 56
Branch analysis from position: 99
Branch analysis from position: 56
Branch analysis from position: 84
2 jumps found. (Code = 43) Position 1 = 87, Position 2 = 89
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
Branch analysis from position: 89
2 jumps found. (Code = 43) Position 1 = 93, Position 2 = 94
Branch analysis from position: 93
Branch analysis from position: 94
Branch analysis from position: 70
2 jumps found. (Code = 46) Position 1 = 72, Position 2 = 74
Branch analysis from position: 72
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 77
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 74
Branch analysis from position: 67
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 128
Branch analysis from position: 128
filename:       /in/59ZXb
function name:  decodePart
number of ops:  137
compiled vars:  !0 = $input, !1 = $nonBasicCharsStart, !2 = $nonBasicChars, !3 = $output, !4 = $n, !5 = $i, !6 = $bias, !7 = $oldi, !8 = $w, !9 = $k, !10 = $digit, !11 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        INIT_FCALL                                               'substr'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 4
          5        DO_ICALL                                         $12     
          6        IS_NOT_IDENTICAL                                         $12, 'xn--'
          7      > JMPZ                                                     ~13, ->9
   37     8    > > RETURN                                                   !0
   39     9    >   INIT_FCALL                                               'substr'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 4
         12        DO_ICALL                                         $14     
         13        ASSIGN                                                   !0, $14
   41    14        INIT_FCALL                                               'strrpos'
         15        SEND_VAR                                                 !0
         16        SEND_VAL                                                 '-'
         17        DO_ICALL                                         $16     
         18        ASSIGN                                           ~17     !1, $16
         19        TYPE_CHECK                                  1018          ~17
         20      > JMPZ                                                     ~18, ->42
   42    21    >   INIT_FCALL                                               'str_split'
         22        INIT_FCALL                                               'substr'
         23        SEND_VAR                                                 !0
         24        ADD                                              ~19     !1, 1
         25        SEND_VAL                                                 ~19
         26        DO_ICALL                                         $20     
         27        SEND_VAR                                                 $20
         28        SEND_VAL                                                 1
         29        DO_ICALL                                         $21     
         30        ASSIGN                                                   !2, $21
   43    31        INIT_FCALL                                               'str_split'
         32        INIT_FCALL                                               'substr'
         33        SEND_VAR                                                 !0
         34        SEND_VAL                                                 0
         35        SEND_VAR                                                 !1
         36        DO_ICALL                                         $23     
         37        SEND_VAR                                                 $23
         38        SEND_VAL                                                 1
         39        DO_ICALL                                         $24     
         40        ASSIGN                                                   !3, $24
         41      > JMP                                                      ->48
   45    42    >   INIT_FCALL                                               'str_split'
         43        SEND_VAR                                                 !0
         44        SEND_VAL                                                 1
         45        DO_ICALL                                         $26     
         46        ASSIGN                                                   !2, $26
   46    47        ASSIGN                                                   !3, <array>
   49    48    >   ASSIGN                                                   !4, 128
         49        ASSIGN                                                   !5, 0
         50        ASSIGN                                                   !6, 72
   50    51      > JMP                                                      ->128
   51    52    >   ASSIGN                                                   !7, !5
   52    53        ASSIGN                                                   !8, 1
   53    54        ASSIGN                                                   !9, 36
         55      > JMP                                                      ->98
   54    56    >   INIT_FCALL                                               'ord'
         57        INIT_FCALL                                               'array_shift'
         58        SEND_REF                                                 !0
         59        DO_ICALL                                         $35     
         60        SEND_VAR                                                 $35
         61        DO_ICALL                                         $36     
         62        ASSIGN                                                   !10, $36
   56    63        IS_SMALLER_OR_EQUAL                              ~38     97, !10
         64      > JMPZ_EX                                          ~38     ~38, ->67
         65    >   IS_SMALLER_OR_EQUAL                              ~39     !10, 122
         66        BOOL                                             ~38     ~39
         67    > > JMPZ                                                     ~38, ->70
   57    68    >   ASSIGN_OP                                     2          !10, 97
         69      > JMP                                                      ->78
   58    70    >   IS_SMALLER_OR_EQUAL                              ~41     48, !10
         71      > JMPZ_EX                                          ~41     ~41, ->74
         72    >   IS_SMALLER_OR_EQUAL                              ~42     !10, 57
         73        BOOL                                             ~41     ~42
         74    > > JMPZ                                                     ~41, ->77
   59    75    >   ASSIGN_OP                                     2          !10, 22
         76      > JMP                                                      ->78
   61    77    > > RETURN                                                   <false>
   64    78    >   MUL                                              ~44     !10, !8
         79        ASSIGN_OP                                     1          !5, ~44
   66    80        IS_SMALLER_OR_EQUAL                                      !9, !6
         81      > JMPZ                                                     ~46, ->84
   67    82    >   ASSIGN                                                   !11, 1
         83      > JMP                                                      ->91
   68    84    >   ADD                                              ~48     !6, 26
         85        IS_SMALLER_OR_EQUAL                                      ~48, !9
         86      > JMPZ                                                     ~49, ->89
   69    87    >   ASSIGN                                                   !11, 26
         88      > JMP                                                      ->91
   71    89    >   SUB                                              ~51     !9, !6
         90        ASSIGN                                                   !11, ~51
   74    91    >   IS_SMALLER                                               !10, !11
         92      > JMPZ                                                     ~53, ->94
   75    93    > > JMP                                                      ->99
   78    94    >   SUB                                              ~54     36, !11
         95        CAST                                          4  ~55     ~54
         96        ASSIGN_OP                                     3          !8, ~55
   79    97        ASSIGN_OP                                     1          !9, 36
         98    > > JMPNZ                                                    <true>, ->56
   81    99    >   INIT_STATIC_METHOD_CALL                                  'IDN', 'punyAdapt'
   82   100        SUB                                              ~58     !5, !7
        101        SEND_VAL                                                 ~58
   83   102        COUNT                                            ~59     !3
        103        ADD                                              ~60     ~59, 1
        104        SEND_VAL                                                 ~60
   84   105        IS_EQUAL                                         ~61     !7, 0
        106        SEND_VAL                                                 ~61
        107        DO_FCALL                                      0  $62     
   81   108        ASSIGN                                                   !6, $62
   86   109        COUNT                                            ~64     !3
        110        ADD                                              ~65     ~64, 1
        111        DIV                                              ~66     !5, ~65
        112        CAST                                          4  ~67     ~66
        113        ASSIGN_OP                                     1          !4, ~67
   87   114        COUNT                                            ~69     !3
        115        ADD                                              ~70     ~69, 1
        116        ASSIGN_OP                                     5          !5, ~70
   88   117        INIT_FCALL                                               'array_splice'
        118        SEND_REF                                                 !3
        119        SEND_VAR                                                 !5
        120        SEND_VAL                                                 0
        121        INIT_STATIC_METHOD_CALL                                  'IDN', 'utf8'
        122        SEND_VAR                                                 !4
        123        DO_FCALL                                      0  $72     
        124        INIT_ARRAY                                       ~73     $72
        125        SEND_VAL                                                 ~73
        126        DO_ICALL                                                 
   89   127        PRE_INC                                                  !5
   50   128    >   ISSET_ISEMPTY_CV                                 ~76     !0
        129        BOOL_NOT                                         ~77     ~76
        130      > JMPNZ                                                    ~77, ->52
   91   131    >   INIT_FCALL                                               'implode'
        132        SEND_VAL                                                 ''
        133        SEND_VAR                                                 !3
        134        DO_ICALL                                         $78     
        135      > RETURN                                                   $78
   92   136*     > 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/59ZXb
function name:  decodeIDN
number of ops:  15
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   94     0  E >   RECV                                             !0      
   97     1        INIT_FCALL                                               'implode'
   98     2        SEND_VAL                                                 '.'
   99     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
  101    14*     > RETURN                                                   null

End of function decodeidn

End of class IDN.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.95 ms | 1420 KiB | 33 Q