3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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, strToHex($testPart)); //echo strToHex($testPart) . "<br>\n"; } $packed = pack('H H H H H H H H', $testParts[0], $testParts[1], $testParts[2], $testParts[3], $testParts[4], $testParts[5], $testParts[6], $testParts[7]); $unpacked = unpack('H H H H H H H 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
Jump found. Position 1 = 10, Position 2 = 19
Branch analysis from position: 10
Jump found. Position 1 = 11, Position 2 = 19
Branch analysis from position: 11
Jump found. Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 19
Jump found. Position 1 = 53, Position 2 = 59
Branch analysis from position: 53
Jump found. Position 1 = 54, Position 2 = 59
Branch analysis from position: 54
Jump found. Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 59
Jump found. Position 1 = -2
Branch analysis from position: 59
Branch analysis from position: 19
filename:       /in/GgelO
function name:  (null)
number of ops:  66
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
-------------------------------------------------------------------------------------
   3     0  E >   NOP                                                      
  12     1        NOP                                                      
  22     2        ASSIGN                                                   !0, 'ffff%3Aeeee%3Adddd%3Acccc%3Abbbb%3Aaaaa%3A9999%3A8888'
  23     3        INIT_FCALL                                               'explode'
         4        SEND_VAL                                                 '%3A'
         5        SEND_VAR                                                 !0
         6        DO_ICALL                                         $9      
         7        ASSIGN                                                   !1, $9
  25     8        ASSIGN                                                   !2, <array>
  27     9      > FE_RESET_R                                       $12     !1, ->19
        10    > > FE_FETCH_R                                               $12, !3, ->19
  28    11    >   INIT_FCALL                                               'array_push'
        12        SEND_REF                                                 !2
        13        INIT_FCALL                                               'strtohex'
        14        SEND_VAR                                                 !3
        15        DO_FCALL                                      0  $13     
        16        SEND_VAR                                                 $13
        17        DO_ICALL                                                 
        18      > JMP                                                      ->10
        19    >   FE_FREE                                                  $12
  32    20        INIT_FCALL                                               'pack'
        21        SEND_VAL                                                 'H+H+H+H+H+H+H+H'
        22        FETCH_DIM_R                                      $15     !1, 0
        23        SEND_VAR                                                 $15
        24        FETCH_DIM_R                                      $16     !1, 1
        25        SEND_VAR                                                 $16
        26        FETCH_DIM_R                                      $17     !1, 2
        27        SEND_VAR                                                 $17
        28        FETCH_DIM_R                                      $18     !1, 3
        29        SEND_VAR                                                 $18
        30        FETCH_DIM_R                                      $19     !1, 4
        31        SEND_VAR                                                 $19
        32        FETCH_DIM_R                                      $20     !1, 5
        33        SEND_VAR                                                 $20
        34        FETCH_DIM_R                                      $21     !1, 6
        35        SEND_VAR                                                 $21
        36        FETCH_DIM_R                                      $22     !1, 7
        37        SEND_VAR                                                 $22
        38        DO_ICALL                                         $23     
        39        ASSIGN                                                   !4, $23
  33    40        INIT_FCALL                                               'unpack'
        41        SEND_VAL                                                 'H+H+H+H+H+H+H+H'
        42        SEND_VAR                                                 !4
        43        DO_ICALL                                         $25     
        44        ASSIGN                                                   !5, $25
  34    45        ASSIGN                                                   !6, <array>
  37    46        INIT_FCALL                                               'var_dump'
        47        SEND_VAR                                                 !4
        48        DO_ICALL                                                 
  38    49        INIT_FCALL                                               'var_dump'
        50        SEND_VAR                                                 !5
        51        DO_ICALL                                                 
  39    52      > FE_RESET_R                                       $30     !5, ->59
        53    > > FE_FETCH_R                                               $30, !7, ->59
  40    54    >   INIT_FCALL                                               'array_push'
        55        SEND_REF                                                 !6
        56        SEND_VAR                                                 !7
        57        DO_ICALL                                                 
        58      > JMP                                                      ->53
        59    >   FE_FREE                                                  $30
  42    60        INIT_FCALL                                               'implode'
        61        SEND_VAL                                                 '%3A'
        62        SEND_VAR                                                 !6
        63        DO_ICALL                                         $32     
        64        ECHO                                                     $32
        65      > RETURN                                                   1

Function strtohex:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 14
Branch analysis from position: 14
Jump found. Position 1 = 17, Position 2 = 4
Branch analysis from position: 17
Jump found. Position 1 = -2
Branch analysis from position: 4
Jump found. Position 1 = 17, Position 2 = 4
Branch analysis from position: 17
Branch analysis from position: 4
filename:       /in/GgelO
function name:  strToHex
number of ops:  19
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                                                      ->14
   8     4    >   INIT_FCALL                                               'dechex'
         5        INIT_FCALL                                               'ord'
         6        FETCH_DIM_R                                      $5      !0, !2
         7        SEND_VAR                                                 $5
         8        DO_ICALL                                         $6      
         9        SEND_VAR                                                 $6
        10        DO_ICALL                                         $7      
        11        ASSIGN_CONCAT                                 0          !1, $7
   6    12        POST_INC                                         ~9      !2
        13        FREE                                                     ~9
        14    >   STRLEN                                           ~10     !0
        15        IS_SMALLER                                       ~11     !2, ~10
        16      > JMPNZ                                                    ~11, ->4
  10    17    > > RETURN                                                   !1
  11    18*     > RETURN                                                   null

End of function strtohex

Function hextostr:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 16
Branch analysis from position: 16
Jump found. Position 1 = 20, Position 2 = 4
Branch analysis from position: 20
Jump found. Position 1 = -2
Branch analysis from position: 4
Jump found. Position 1 = 20, Position 2 = 4
Branch analysis from position: 20
Branch analysis from position: 4
filename:       /in/GgelO
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_CONCAT                                 0          !1, $10
  15    15        ASSIGN_ADD                                    0          !2, 2
        16    >   STRLEN                                           ~13     !0
        17        SUB                                              ~14     ~13, 1
        18        IS_SMALLER                                       ~15     !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 7.2.0