3v4l.org

run code in 300+ PHP versions simultaneously
<?php function normalise_ip($address) { if (preg_match('/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/', $address, $matches)) { // IPv4 address $num = 0; for ($i = 1; $i <= 4; $i++) { $octet = (int) $matches[$i]; if ($octet > 255) { return false; } $num |= $octet << ((4 - $i) * 8); } return sprintf('00000000000000000000ffff%04x', $num); } else if (preg_match('/\[?((?:[0-9a-f]{1,4}:|::)+[0-9a-f]{1,4})]?/i', strtolower($address), $matches)) { // IPv6 address $parts = explode(':', $matches[1]); $numParts = count($parts); if ($parts[0] === '') { array_splice($parts, 0, 2, array_fill(0, 8 - ($numParts - 2), '0000')); } else if ($parts[$numParts - 1] === '') { array_splice($parts, $numParts - 2, 2, array_fill(0, 8 - ($numParts - 2), '0000')); } else { foreach ($parts as $i => $part) { if ($part === '') { array_splice($parts, $i, 1, array_fill(0, 8 - ($numParts - 1), '0000')); } } } foreach ($parts as &$part) { $part = sprintf('%04s', $part); } return implode('', $parts); } else { // invalid return false; } } echo normalise_ip('192.168.0.1') . "\n"; echo normalise_ip('[::ffff:C0A8:0001]') . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2mVP6
function name:  (null)
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   INIT_FCALL                                               'normalise_ip'
          1        SEND_VAL                                                 '192.168.0.1'
          2        DO_FCALL                                      0  $0      
          3        CONCAT                                           ~1      $0, '%0A'
          4        ECHO                                                     ~1
   39     5        INIT_FCALL                                               'normalise_ip'
          6        SEND_VAL                                                 '%5B%3A%3Affff%3AC0A8%3A0001%5D'
          7        DO_FCALL                                      0  $2      
          8        CONCAT                                           ~3      $2, '%0A'
          9        ECHO                                                     ~3
         10      > RETURN                                                   1

Function normalise_ip:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 29
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 10
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 10
Branch analysis from position: 23
Branch analysis from position: 10
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 117
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 63
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 102
Branch analysis from position: 102
2 jumps found. (Code = 125) Position 1 = 103, Position 2 = 110
Branch analysis from position: 103
2 jumps found. (Code = 126) Position 1 = 104, Position 2 = 110
Branch analysis from position: 104
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
Branch analysis from position: 110
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 110
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 82
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 102
Branch analysis from position: 102
Branch analysis from position: 82
2 jumps found. (Code = 77) Position 1 = 83, Position 2 = 101
Branch analysis from position: 83
2 jumps found. (Code = 78) Position 1 = 84, Position 2 = 101
Branch analysis from position: 84
2 jumps found. (Code = 43) Position 1 = 87, Position 2 = 100
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 83
Branch analysis from position: 83
Branch analysis from position: 100
Branch analysis from position: 101
2 jumps found. (Code = 125) Position 1 = 103, Position 2 = 110
Branch analysis from position: 103
Branch analysis from position: 110
Branch analysis from position: 101
Branch analysis from position: 117
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2mVP6
function name:  normalise_ip
number of ops:  119
compiled vars:  !0 = $address, !1 = $matches, !2 = $num, !3 = $i, !4 = $octet, !5 = $parts, !6 = $numParts, !7 = $part
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2F%28%5Cd%7B1%2C3%7D%29%5C.%28%5Cd%7B1%2C3%7D%29%5C.%28%5Cd%7B1%2C3%7D%29%5C.%28%5Cd%7B1%2C3%7D%29%2F'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                         $8      
          6      > JMPZ                                                     $8, ->29
    6     7    >   ASSIGN                                                   !2, 0
    7     8        ASSIGN                                                   !3, 1
          9      > JMP                                                      ->21
    8    10    >   FETCH_DIM_R                                      ~11     !1, !3
         11        CAST                                          4  ~12     ~11
         12        ASSIGN                                                   !4, ~12
    9    13        IS_SMALLER                                               255, !4
         14      > JMPZ                                                     ~14, ->16
   10    15    > > RETURN                                                   <false>
   12    16    >   SUB                                              ~15     4, !3
         17        MUL                                              ~16     ~15, 8
         18        SL                                               ~17     !4, ~16
         19        ASSIGN_OP                                     9          !2, ~17
    7    20        PRE_INC                                                  !3
         21    >   IS_SMALLER_OR_EQUAL                                      !3, 4
         22      > JMPNZ                                                    ~20, ->10
   14    23    >   INIT_FCALL                                               'sprintf'
         24        SEND_VAL                                                 '00000000000000000000ffff%2504x'
         25        SEND_VAR                                                 !2
         26        DO_ICALL                                         $21     
         27      > RETURN                                                   $21
         28*       JMP                                                      ->118
   15    29    >   INIT_FCALL                                               'preg_match'
         30        SEND_VAL                                                 '%2F%5C%5B%3F%28%28%3F%3A%5B0-9a-f%5D%7B1%2C4%7D%3A%7C%3A%3A%29%2B%5B0-9a-f%5D%7B1%2C4%7D%29%5D%3F%2Fi'
         31        INIT_FCALL                                               'strtolower'
         32        SEND_VAR                                                 !0
         33        DO_ICALL                                         $22     
         34        SEND_VAR                                                 $22
         35        SEND_REF                                                 !1
         36        DO_ICALL                                         $23     
         37      > JMPZ                                                     $23, ->117
   16    38    >   INIT_FCALL                                               'explode'
         39        SEND_VAL                                                 '%3A'
         40        FETCH_DIM_R                                      ~24     !1, 1
         41        SEND_VAL                                                 ~24
         42        DO_ICALL                                         $25     
         43        ASSIGN                                                   !5, $25
   17    44        COUNT                                            ~27     !5
         45        ASSIGN                                                   !6, ~27
   18    46        FETCH_DIM_R                                      ~29     !5, 0
         47        IS_IDENTICAL                                             ~29, ''
         48      > JMPZ                                                     ~30, ->63
   19    49    >   INIT_FCALL                                               'array_splice'
         50        SEND_REF                                                 !5
         51        SEND_VAL                                                 0
         52        SEND_VAL                                                 2
         53        INIT_FCALL                                               'array_fill'
         54        SEND_VAL                                                 0
         55        SUB                                              ~31     !6, 2
         56        SUB                                              ~32     8, ~31
         57        SEND_VAL                                                 ~32
         58        SEND_VAL                                                 '0000'
         59        DO_ICALL                                         $33     
         60        SEND_VAR                                                 $33
         61        DO_ICALL                                                 
         62      > JMP                                                      ->102
   20    63    >   SUB                                              ~35     !6, 1
         64        FETCH_DIM_R                                      ~36     !5, ~35
         65        IS_IDENTICAL                                             ~36, ''
         66      > JMPZ                                                     ~37, ->82
   21    67    >   INIT_FCALL                                               'array_splice'
         68        SEND_REF                                                 !5
         69        SUB                                              ~38     !6, 2
         70        SEND_VAL                                                 ~38
         71        SEND_VAL                                                 2
         72        INIT_FCALL                                               'array_fill'
         73        SEND_VAL                                                 0
         74        SUB                                              ~39     !6, 2
         75        SUB                                              ~40     8, ~39
         76        SEND_VAL                                                 ~40
         77        SEND_VAL                                                 '0000'
         78        DO_ICALL                                         $41     
         79        SEND_VAR                                                 $41
         80        DO_ICALL                                                 
         81      > JMP                                                      ->102
   23    82    > > FE_RESET_R                                       $43     !5, ->101
         83    > > FE_FETCH_R                                       ~44     $43, !7, ->101
         84    >   ASSIGN                                                   !3, ~44
   24    85        IS_IDENTICAL                                             !7, ''
         86      > JMPZ                                                     ~46, ->100
   25    87    >   INIT_FCALL                                               'array_splice'
         88        SEND_REF                                                 !5
         89        SEND_VAR                                                 !3
         90        SEND_VAL                                                 1
         91        INIT_FCALL                                               'array_fill'
         92        SEND_VAL                                                 0
         93        SUB                                              ~47     !6, 1
         94        SUB                                              ~48     8, ~47
         95        SEND_VAL                                                 ~48
         96        SEND_VAL                                                 '0000'
         97        DO_ICALL                                         $49     
         98        SEND_VAR                                                 $49
         99        DO_ICALL                                                 
   23   100    > > JMP                                                      ->83
        101    >   FE_FREE                                                  $43
   29   102    > > FE_RESET_RW                                      $51     !5, ->110
        103    > > FE_FETCH_RW                                              $51, !7, ->110
   30   104    >   INIT_FCALL                                               'sprintf'
        105        SEND_VAL                                                 '%2504s'
        106        SEND_VAR                                                 !7
        107        DO_ICALL                                         $52     
        108        ASSIGN                                                   !7, $52
   29   109      > JMP                                                      ->103
        110    >   FE_FREE                                                  $51
   32   111        INIT_FCALL                                               'implode'
        112        SEND_VAL                                                 ''
        113        SEND_VAR                                                 !5
        114        DO_ICALL                                         $54     
        115      > RETURN                                                   $54
        116*       JMP                                                      ->118
   34   117    > > RETURN                                                   <false>
   36   118*     > RETURN                                                   null

End of function normalise_ip

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.25 ms | 1410 KiB | 29 Q