3v4l.org

run code in 500+ PHP versions simultaneously
<?php function convertIPv6To4($ip) { // validate if given IP is a proper IPv6 address if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) { // validate if given IP is a proper IPv4 address if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) { // ip address is invalid return ''; } return $ip; } // check if ip is a masked IPv4 address if (substr($ip, 0, 7) == '::ffff:') { $ip = substr($ip, 7); if (preg_match('~^([a-f0-9]{1,4}):([a-f0-9]{1,4})$~', $ip, $matches)) { $ip = array( base_convert($matches[1], 16, 10), base_convert($matches[2], 16, 10) ); $ipParts = array(); $tmp = $ip[0] % 256; $ipParts[] = ($ip[0] - $tmp) / 256; $ipParts[] = $tmp; $tmp = $ip[1] % 256; $ipParts[] = ($ip[1] - $tmp) / 256; $ipParts[] = $tmp; return implode('.', $ipParts); } else { return $ip; } } else { // given ip is an IPv6 address and cannot be converted return $ip; } } echo convertIPv6To4('::ffff:bc65:d048');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dVq82
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   43     0  E >   INIT_FCALL                                                   'convertipv6to4'
          1        SEND_VAL                                                     '%3A%3Affff%3Abc65%3Ad048'
          2        DO_FCALL                                          0  $0      
          3        ECHO                                                         $0
          4      > RETURN                                                       1

Function convertipv6to4:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
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
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 70
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 68
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 70
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dVq82
function name:  convertIPv6To4
number of ops:  72
compiled vars:  !0 = $ip, !1 = $matches, !2 = $ipParts, !3 = $tmp
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   RECV                                                 !0      
    4     1        INIT_FCALL                                                   'filter_var'
          2        SEND_VAR                                                     !0
          3        SEND_VAL                                                     275
          4        SEND_VAL                                                     2097152
          5        DO_ICALL                                             $4      
          6        TYPE_CHECK                                        4          $4
          7      > JMPZ                                                         ~5, ->17
    6     8    >   INIT_FCALL                                                   'filter_var'
          9        SEND_VAR                                                     !0
         10        SEND_VAL                                                     275
         11        SEND_VAL                                                     1048576
         12        DO_ICALL                                             $6      
         13        TYPE_CHECK                                        4          $6
         14      > JMPZ                                                         ~7, ->16
    8    15    > > RETURN                                                       ''
   11    16    > > RETURN                                                       !0
   15    17    >   FRAMELESS_ICALL_3                substr              ~8      !0, 0
         18        OP_DATA                                                      7
         19        IS_EQUAL                                                     ~8, '%3A%3Affff%3A'
         20      > JMPZ                                                         ~9, ->70
   16    21    >   FRAMELESS_ICALL_2                substr              ~10     !0, 7
         22        ASSIGN                                                       !0, ~10
   17    23        INIT_FCALL                                                   'preg_match'
         24        SEND_VAL                                                     '%7E%5E%28%5Ba-f0-9%5D%7B1%2C4%7D%29%3A%28%5Ba-f0-9%5D%7B1%2C4%7D%29%24%7E'
         25        SEND_VAR                                                     !0
         26        SEND_REF                                                     !1
         27        DO_ICALL                                             $12     
         28      > JMPZ                                                         $12, ->68
   19    29    >   INIT_FCALL                                                   'base_convert'
         30        FETCH_DIM_R                                          ~13     !1, 1
         31        SEND_VAL                                                     ~13
         32        SEND_VAL                                                     16
         33        SEND_VAL                                                     10
         34        DO_ICALL                                             $14     
         35        INIT_ARRAY                                           ~15     $14
   20    36        INIT_FCALL                                                   'base_convert'
         37        FETCH_DIM_R                                          ~16     !1, 2
         38        SEND_VAL                                                     ~16
         39        SEND_VAL                                                     16
         40        SEND_VAL                                                     10
         41        DO_ICALL                                             $17     
         42        ADD_ARRAY_ELEMENT                                    ~15     $17
   18    43        ASSIGN                                                       !0, ~15
   23    44        ASSIGN                                                       !2, <array>
   24    45        FETCH_DIM_R                                          ~20     !0, 0
         46        MOD                                                  ~21     ~20, 256
         47        ASSIGN                                                       !3, ~21
   25    48        FETCH_DIM_R                                          ~24     !0, 0
         49        SUB                                                  ~25     ~24, !3
         50        DIV                                                  ~26     ~25, 256
         51        ASSIGN_DIM                                                   !2
         52        OP_DATA                                                      ~26
   26    53        ASSIGN_DIM                                                   !2
         54        OP_DATA                                                      !3
   27    55        FETCH_DIM_R                                          ~28     !0, 1
         56        MOD                                                  ~29     ~28, 256
         57        ASSIGN                                                       !3, ~29
   28    58        FETCH_DIM_R                                          ~32     !0, 1
         59        SUB                                                  ~33     ~32, !3
         60        DIV                                                  ~34     ~33, 256
         61        ASSIGN_DIM                                                   !2
         62        OP_DATA                                                      ~34
   29    63        ASSIGN_DIM                                                   !2
         64        OP_DATA                                                      !3
   31    65        FRAMELESS_ICALL_2                implode             ~36     '.', !2
         66      > RETURN                                                       ~36
   17    67*       JMP                                                          ->69
   34    68    > > RETURN                                                       !0
   15    69*       JMP                                                          ->71
   39    70    > > RETURN                                                       !0
   41    71*     > RETURN                                                       null

End of function convertipv6to4

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
168.17 ms | 2946 KiB | 17 Q