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('nvH*', '0x'.$testParts[0], '0x'.$testParts[1], '0x'.$testParts[2], '0x'.$testParts[3], '0x'.$testParts[4], '0x'.$testParts[5], '0x'.$testParts[6], '0x'.$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 = 56, Position 2 = 62
Branch analysis from position: 56
2 jumps found. (Code = 78) Position 1 = 57, Position 2 = 62
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
Branch analysis from position: 14
filename:       /in/s43ef
function name:  (null)
number of ops:  69
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                                                 'nvH%2A'
         17        FETCH_DIM_R                                      ~14     !1, 0
         18        CONCAT                                           ~15     '0x', ~14
         19        SEND_VAL                                                 ~15
         20        FETCH_DIM_R                                      ~16     !1, 1
         21        CONCAT                                           ~17     '0x', ~16
         22        SEND_VAL                                                 ~17
         23        FETCH_DIM_R                                      ~18     !1, 2
         24        CONCAT                                           ~19     '0x', ~18
         25        SEND_VAL                                                 ~19
         26        FETCH_DIM_R                                      ~20     !1, 3
         27        CONCAT                                           ~21     '0x', ~20
         28        SEND_VAL                                                 ~21
         29        FETCH_DIM_R                                      ~22     !1, 4
         30        CONCAT                                           ~23     '0x', ~22
         31        SEND_VAL                                                 ~23
         32        FETCH_DIM_R                                      ~24     !1, 5
         33        CONCAT                                           ~25     '0x', ~24
         34        SEND_VAL                                                 ~25
         35        FETCH_DIM_R                                      ~26     !1, 6
         36        CONCAT                                           ~27     '0x', ~26
         37        SEND_VAL                                                 ~27
         38        FETCH_DIM_R                                      ~28     !1, 7
         39        CONCAT                                           ~29     '0x', ~28
         40        SEND_VAL                                                 ~29
         41        DO_ICALL                                         $30     
         42        ASSIGN                                                   !4, $30
   33    43        INIT_FCALL                                               'unpack'
         44        SEND_VAL                                                 'H%2A'
         45        SEND_VAR                                                 !4
         46        DO_ICALL                                         $32     
         47        ASSIGN                                                   !5, $32
   34    48        ASSIGN                                                   !6, <array>
   37    49        INIT_FCALL                                               'var_dump'
         50        SEND_VAR                                                 !4
         51        DO_ICALL                                                 
   38    52        INIT_FCALL                                               'var_dump'
         53        SEND_VAR                                                 !5
         54        DO_ICALL                                                 
   39    55      > FE_RESET_R                                       $37     !5, ->62
         56    > > FE_FETCH_R                                               $37, !7, ->62
   40    57    >   INIT_FCALL                                               'array_push'
         58        SEND_REF                                                 !6
         59        SEND_VAR                                                 !7
         60        DO_ICALL                                                 
   39    61      > JMP                                                      ->56
         62    >   FE_FREE                                                  $37
   42    63        INIT_FCALL                                               'implode'
         64        SEND_VAL                                                 '%3A'
         65        SEND_VAR                                                 !6
         66        DO_ICALL                                         $39     
         67        ECHO                                                     $39
   44    68      > 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/s43ef
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/s43ef
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:
164.31 ms | 1396 KiB | 33 Q