3v4l.org

run code in 300+ PHP versions simultaneously
<?php function strToHex($string) { $hex=''; for ($i=0; $i < strlen($string); $i++) { $hex .= dechex(ord($string[$i])); } return $hex; } function hexToStr($hex) { $string=''; for ($i=0; $i < strlen($hex)-1; $i+=2) { $string .= chr(hexdec($hex[$i].$hex[$i+1])); } return $string; } $test = "ffff:eeee:dddd:cccc:bbbb:aaaa:9999:8888"; $testParts = explode(':', $test); $testHex = array(); foreach($testParts as $testPart){ array_push($testHex, $testPart); //echo strToHex($testPart) . "<br>\n"; } $packed = pack('H*', $testParts[0], $testParts[1], $testParts[2], $testParts[3], $testParts[4], $testParts[5], $testParts[6], $testParts[7]); $unpacked = unpack('H*', $packed); $unpackedString = array(); //var_dump($testParts); //var_dump($testHex); var_dump($packed); var_dump($unpacked); foreach($unpacked as $unpack){ array_push($unpackedString, $unpack); } echo implode(':', $unpackedString); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 48, Position 2 = 54
Branch analysis from position: 48
2 jumps found. (Code = 78) Position 1 = 49, Position 2 = 54
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
Branch analysis from position: 14
filename:       /in/8YLsZ
function name:  (null)
number of ops:  61
compiled vars:  !0 = $test, !1 = $testParts, !2 = $testHex, !3 = $testPart, !4 = $packed, !5 = $unpacked, !6 = $unpackedString, !7 = $unpack
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                   !0, 'ffff%3Aeeee%3Adddd%3Acccc%3Abbbb%3Aaaaa%3A9999%3A8888'
   23     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%3A'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $9      
          5        ASSIGN                                                   !1, $9
   25     6        ASSIGN                                                   !2, <array>
   27     7      > FE_RESET_R                                       $12     !1, ->14
          8    > > FE_FETCH_R                                               $12, !3, ->14
   28     9    >   INIT_FCALL                                               'array_push'
         10        SEND_REF                                                 !2
         11        SEND_VAR                                                 !3
         12        DO_ICALL                                                 
   27    13      > JMP                                                      ->8
         14    >   FE_FREE                                                  $12
   32    15        INIT_FCALL                                               'pack'
         16        SEND_VAL                                                 'H%2A'
         17        FETCH_DIM_R                                      ~14     !1, 0
         18        SEND_VAL                                                 ~14
         19        FETCH_DIM_R                                      ~15     !1, 1
         20        SEND_VAL                                                 ~15
         21        FETCH_DIM_R                                      ~16     !1, 2
         22        SEND_VAL                                                 ~16
         23        FETCH_DIM_R                                      ~17     !1, 3
         24        SEND_VAL                                                 ~17
         25        FETCH_DIM_R                                      ~18     !1, 4
         26        SEND_VAL                                                 ~18
         27        FETCH_DIM_R                                      ~19     !1, 5
         28        SEND_VAL                                                 ~19
         29        FETCH_DIM_R                                      ~20     !1, 6
         30        SEND_VAL                                                 ~20
         31        FETCH_DIM_R                                      ~21     !1, 7
         32        SEND_VAL                                                 ~21
         33        DO_ICALL                                         $22     
         34        ASSIGN                                                   !4, $22
   33    35        INIT_FCALL                                               'unpack'
         36        SEND_VAL                                                 'H%2A'
         37        SEND_VAR                                                 !4
         38        DO_ICALL                                         $24     
         39        ASSIGN                                                   !5, $24
   34    40        ASSIGN                                                   !6, <array>
   37    41        INIT_FCALL                                               'var_dump'
         42        SEND_VAR                                                 !4
         43        DO_ICALL                                                 
   38    44        INIT_FCALL                                               'var_dump'
         45        SEND_VAR                                                 !5
         46        DO_ICALL                                                 
   39    47      > FE_RESET_R                                       $29     !5, ->54
         48    > > FE_FETCH_R                                               $29, !7, ->54
   40    49    >   INIT_FCALL                                               'array_push'
         50        SEND_REF                                                 !6
         51        SEND_VAR                                                 !7
         52        DO_ICALL                                                 
   39    53      > JMP                                                      ->48
         54    >   FE_FREE                                                  $29
   42    55        INIT_FCALL                                               'implode'
         56        SEND_VAL                                                 '%3A'
         57        SEND_VAR                                                 !6
         58        DO_ICALL                                         $31     
         59        ECHO                                                     $31
   44    60      > RETURN                                                   1

Function strtohex:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 4
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 4
Branch analysis from position: 16
Branch analysis from position: 4
filename:       /in/8YLsZ
function name:  strToHex
number of ops:  18
compiled vars:  !0 = $string, !1 = $hex, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, ''
    6     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->13
    8     4    >   INIT_FCALL                                               'dechex'
          5        INIT_FCALL                                               'ord'
          6        FETCH_DIM_R                                      ~5      !0, !2
          7        SEND_VAL                                                 ~5
          8        DO_ICALL                                         $6      
          9        SEND_VAR                                                 $6
         10        DO_ICALL                                         $7      
         11        ASSIGN_OP                                     8          !1, $7
    6    12        PRE_INC                                                  !2
         13    >   STRLEN                                           ~10     !0
         14        IS_SMALLER                                               !2, ~10
         15      > JMPNZ                                                    ~11, ->4
   10    16    > > RETURN                                                   !1
   11    17*     > RETURN                                                   null

End of function strtohex

Function hextostr:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 4
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 4
Branch analysis from position: 20
Branch analysis from position: 4
filename:       /in/8YLsZ
function name:  hexToStr
number of ops:  22
compiled vars:  !0 = $hex, !1 = $string, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   14     1        ASSIGN                                                   !1, ''
   15     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->16
   17     4    >   INIT_FCALL                                               'chr'
          5        INIT_FCALL                                               'hexdec'
          6        FETCH_DIM_R                                      ~5      !0, !2
          7        ADD                                              ~6      !2, 1
          8        FETCH_DIM_R                                      ~7      !0, ~6
          9        CONCAT                                           ~8      ~5, ~7
         10        SEND_VAL                                                 ~8
         11        DO_ICALL                                         $9      
         12        SEND_VAR                                                 $9
         13        DO_ICALL                                         $10     
         14        ASSIGN_OP                                     8          !1, $10
   15    15        ASSIGN_OP                                     1          !2, 2
         16    >   STRLEN                                           ~13     !0
         17        SUB                                              ~14     ~13, 1
         18        IS_SMALLER                                               !2, ~14
         19      > JMPNZ                                                    ~15, ->4
   19    20    > > RETURN                                                   !1
   20    21*     > RETURN                                                   null

End of function hextostr

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.25 ms | 1404 KiB | 33 Q