3v4l.org

run code in 300+ 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('2003:66:4f14:d880:7075:9457:3857:29ec') ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Dh4M3
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                                                 '2003%3A66%3A4f14%3Ad880%3A7075%3A9457%3A3857%3A29ec'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
   44     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 = 24, Position 2 = 79
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 77
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 79
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Dh4M3
function name:  convertIPv6To4
number of ops:  81
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    >   INIT_FCALL                                               'substr'
         18        SEND_VAR                                                 !0
         19        SEND_VAL                                                 0
         20        SEND_VAL                                                 7
         21        DO_ICALL                                         $8      
         22        IS_EQUAL                                                 $8, '%3A%3Affff%3A'
         23      > JMPZ                                                     ~9, ->79
   16    24    >   INIT_FCALL                                               'substr'
         25        SEND_VAR                                                 !0
         26        SEND_VAL                                                 7
         27        DO_ICALL                                         $10     
         28        ASSIGN                                                   !0, $10
   17    29        INIT_FCALL                                               'preg_match'
         30        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'
         31        SEND_VAR                                                 !0
         32        SEND_REF                                                 !1
         33        DO_ICALL                                         $12     
         34      > JMPZ                                                     $12, ->77
   19    35    >   INIT_FCALL                                               'base_convert'
         36        FETCH_DIM_R                                      ~13     !1, 1
         37        SEND_VAL                                                 ~13
         38        SEND_VAL                                                 16
         39        SEND_VAL                                                 10
         40        DO_ICALL                                         $14     
         41        INIT_ARRAY                                       ~15     $14
   20    42        INIT_FCALL                                               'base_convert'
         43        FETCH_DIM_R                                      ~16     !1, 2
         44        SEND_VAL                                                 ~16
         45        SEND_VAL                                                 16
         46        SEND_VAL                                                 10
         47        DO_ICALL                                         $17     
         48        ADD_ARRAY_ELEMENT                                ~15     $17
   18    49        ASSIGN                                                   !0, ~15
   23    50        ASSIGN                                                   !2, <array>
   24    51        FETCH_DIM_R                                      ~20     !0, 0
         52        MOD                                              ~21     ~20, 256
         53        ASSIGN                                                   !3, ~21
   25    54        FETCH_DIM_R                                      ~24     !0, 0
         55        SUB                                              ~25     ~24, !3
         56        DIV                                              ~26     ~25, 256
         57        ASSIGN_DIM                                               !2
         58        OP_DATA                                                  ~26
   26    59        ASSIGN_DIM                                               !2
         60        OP_DATA                                                  !3
   27    61        FETCH_DIM_R                                      ~28     !0, 1
         62        MOD                                              ~29     ~28, 256
         63        ASSIGN                                                   !3, ~29
   28    64        FETCH_DIM_R                                      ~32     !0, 1
         65        SUB                                              ~33     ~32, !3
         66        DIV                                              ~34     ~33, 256
         67        ASSIGN_DIM                                               !2
         68        OP_DATA                                                  ~34
   29    69        ASSIGN_DIM                                               !2
         70        OP_DATA                                                  !3
   31    71        INIT_FCALL                                               'implode'
         72        SEND_VAL                                                 '.'
         73        SEND_VAR                                                 !2
         74        DO_ICALL                                         $36     
         75      > RETURN                                                   $36
         76*       JMP                                                      ->78
   34    77    > > RETURN                                                   !0
         78*       JMP                                                      ->80
   39    79    > > RETURN                                                   !0
   41    80*     > RETURN                                                   null

End of function convertipv6to4

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.89 ms | 1406 KiB | 24 Q