3v4l.org

run code in 300+ PHP versions simultaneously
<?php class LZW { function compress($uncompressed) { $dictSize = 256; $dictionary = array(); for ($i = 0; $i < 256; $i++) { $dictionary[chr($i)] = $i; } $w = ""; $result = ""; for ($i = 0; $i < strlen($uncompressed); $i++) { $c = $this->charAt($uncompressed, $i); $wc = $w.$c; if (isset($dictionary[$wc])) { $w = $wc; } else { if ($result != "") { $result .= ",".$dictionary[$w]; } else { $result .= $dictionary[$w]; } $dictionary[$wc] = $dictSize++; $w = "".$c; } } if ($w != "") { if ($result != "") { $result .= ",".$dictionary[$w]; } else { $result .= $dictionary[$w]; } } return $result; } function decompress($compressed) { $compressed = explode(",", $compressed); $dictSize = 256; $dictionary = array(); for ($i = 1; $i < 256; $i++) { $dictionary[$i] = chr($i); } $w = chr($compressed[0]); $result = $w; for ($i = 1; $i < count($compressed); $i++) { $entry = ""; $k = $compressed[$i]; if (isset($dictionary[$k])) { $entry = $dictionary[$k]; } else if ($k == $dictSize) { $entry = $w.$this->charAt($w, 0); } else { return null; } $result .= $entry; $dictionary[$dictSize++] = $w.$this->charAt($entry, 0); $w = $entry; } return $result; } function charAt($string, $index){ if($index < mb_strlen($string)){ return mb_substr($string, $index, 1); } else{ return -1; } } } $lzw = new LZW(); echo $lzw->decompress("dGl0bGUgw4ljaGFuZ2VzIExNNwoKZVNtaWxlLT4rTE03OiBBcnRpY2xlCkxNNy0-LQAWBjogUmV0b3VyABQJACUPUkVDACEPTURTAEkQT1AAPhZPUAoAaAUtPgBlCEltYWdlIHN0b2Nr");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0iiFb
function name:  (null)
number of ops:  8
compiled vars:  !0 = $lzw
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   NEW                                              $1      'LZW'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   70     3        INIT_METHOD_CALL                                         !0, 'decompress'
          4        SEND_VAL_EX                                              'dGl0bGUgw4ljaGFuZ2VzIExNNwoKZVNtaWxlLT4rTE03OiBBcnRpY2xlCkxNNy0-LQAWBjogUmV0b3VyABQJACUPUkVDACEPTURTAEkQT1AAPhZPUAoAaAUtPgBlCEltYWdlIHN0b2Nr'
          5        DO_FCALL                                      0  $4      
          6        ECHO                                                     $4
          7      > RETURN                                                   1

Class LZW:
Function compress:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 5
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 17
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 55
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 53
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 17
Branch analysis from position: 45
Branch analysis from position: 17
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 34
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 17
Branch analysis from position: 45
Branch analysis from position: 17
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 17
Branch analysis from position: 45
Branch analysis from position: 17
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 5
Branch analysis from position: 13
Branch analysis from position: 5
filename:       /in/0iiFb
function name:  compress
number of ops:  57
compiled vars:  !0 = $uncompressed, !1 = $dictSize, !2 = $dictionary, !3 = $i, !4 = $w, !5 = $result, !6 = $c, !7 = $wc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, 256
    5     2        ASSIGN                                                   !2, <array>
    6     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->11
    7     5    >   INIT_FCALL                                               'chr'
          6        SEND_VAR                                                 !3
          7        DO_ICALL                                         $11     
          8        ASSIGN_DIM                                               !2, $11
          9        OP_DATA                                                  !3
    6    10        PRE_INC                                                  !3
         11    >   IS_SMALLER                                               !3, 256
         12      > JMPNZ                                                    ~14, ->5
    9    13    >   ASSIGN                                                   !4, ''
   10    14        ASSIGN                                                   !5, ''
   11    15        ASSIGN                                                   !3, 0
         16      > JMP                                                      ->42
   12    17    >   INIT_METHOD_CALL                                         'charAt'
         18        SEND_VAR_EX                                              !0
         19        SEND_VAR_EX                                              !3
         20        DO_FCALL                                      0  $18     
         21        ASSIGN                                                   !6, $18
   13    22        CONCAT                                           ~20     !4, !6
         23        ASSIGN                                                   !7, ~20
   14    24        ISSET_ISEMPTY_DIM_OBJ                         0          !2, !7
         25      > JMPZ                                                     ~22, ->28
   15    26    >   ASSIGN                                                   !4, !7
         27      > JMP                                                      ->41
   17    28    >   IS_NOT_EQUAL                                             !5, ''
         29      > JMPZ                                                     ~24, ->34
   18    30    >   FETCH_DIM_R                                      ~25     !2, !4
         31        CONCAT                                           ~26     '%2C', ~25
         32        ASSIGN_OP                                     8          !5, ~26
         33      > JMP                                                      ->36
   20    34    >   FETCH_DIM_R                                      ~28     !2, !4
         35        ASSIGN_OP                                     8          !5, ~28
   22    36    >   POST_INC                                         ~31     !1
         37        ASSIGN_DIM                                               !2, !7
         38        OP_DATA                                                  ~31
   23    39        CONCAT                                           ~32     '', !6
         40        ASSIGN                                                   !4, ~32
   11    41    >   PRE_INC                                                  !3
         42    >   STRLEN                                           ~35     !0
         43        IS_SMALLER                                               !3, ~35
         44      > JMPNZ                                                    ~36, ->17
   26    45    >   IS_NOT_EQUAL                                             !4, ''
         46      > JMPZ                                                     ~37, ->55
   27    47    >   IS_NOT_EQUAL                                             !5, ''
         48      > JMPZ                                                     ~38, ->53
   28    49    >   FETCH_DIM_R                                      ~39     !2, !4
         50        CONCAT                                           ~40     '%2C', ~39
         51        ASSIGN_OP                                     8          !5, ~40
         52      > JMP                                                      ->55
   30    53    >   FETCH_DIM_R                                      ~42     !2, !4
         54        ASSIGN_OP                                     8          !5, ~42
   33    55    > > RETURN                                                   !5
   34    56*     > RETURN                                                   null

End of function compress

Function decompress:
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 = 18, Position 2 = 10
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 26
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 34
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 26
Branch analysis from position: 58
Branch analysis from position: 26
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 43
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 10
Branch analysis from position: 18
Branch analysis from position: 10
filename:       /in/0iiFb
function name:  decompress
number of ops:  60
compiled vars:  !0 = $compressed, !1 = $dictSize, !2 = $dictionary, !3 = $i, !4 = $w, !5 = $result, !6 = $entry, !7 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%2C'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $8      
          5        ASSIGN                                                   !0, $8
   37     6        ASSIGN                                                   !1, 256
   38     7        ASSIGN                                                   !2, <array>
   39     8        ASSIGN                                                   !3, 1
          9      > JMP                                                      ->16
   40    10    >   INIT_FCALL                                               'chr'
         11        SEND_VAR                                                 !3
         12        DO_ICALL                                         $14     
         13        ASSIGN_DIM                                               !2, !3
         14        OP_DATA                                                  $14
   39    15        PRE_INC                                                  !3
         16    >   IS_SMALLER                                               !3, 256
         17      > JMPNZ                                                    ~16, ->10
   42    18    >   INIT_FCALL                                               'chr'
         19        FETCH_DIM_R                                      ~17     !0, 0
         20        SEND_VAL                                                 ~17
         21        DO_ICALL                                         $18     
         22        ASSIGN                                                   !4, $18
   43    23        ASSIGN                                                   !5, !4
   44    24        ASSIGN                                                   !3, 1
         25      > JMP                                                      ->55
   45    26    >   ASSIGN                                                   !6, ''
   46    27        FETCH_DIM_R                                      ~23     !0, !3
         28        ASSIGN                                                   !7, ~23
   47    29        ISSET_ISEMPTY_DIM_OBJ                         0          !2, !7
         30      > JMPZ                                                     ~25, ->34
   48    31    >   FETCH_DIM_R                                      ~26     !2, !7
         32        ASSIGN                                                   !6, ~26
         33      > JMP                                                      ->44
   49    34    >   IS_EQUAL                                                 !7, !1
         35      > JMPZ                                                     ~28, ->43
   50    36    >   INIT_METHOD_CALL                                         'charAt'
         37        SEND_VAR_EX                                              !4
         38        SEND_VAL_EX                                              0
         39        DO_FCALL                                      0  $29     
         40        CONCAT                                           ~30     !4, $29
         41        ASSIGN                                                   !6, ~30
         42      > JMP                                                      ->44
   52    43    > > RETURN                                                   null
   54    44    >   ASSIGN_OP                                     8          !5, !6
   55    45        POST_INC                                         ~33     !1
         46        INIT_METHOD_CALL                                         'charAt'
         47        SEND_VAR_EX                                              !6
         48        SEND_VAL_EX                                              0
         49        DO_FCALL                                      0  $35     
         50        CONCAT                                           ~36     !4, $35
         51        ASSIGN_DIM                                               !2, ~33
         52        OP_DATA                                                  ~36
   56    53        ASSIGN                                                   !4, !6
   44    54        PRE_INC                                                  !3
         55    >   COUNT                                            ~39     !0
         56        IS_SMALLER                                               !3, ~39
         57      > JMPNZ                                                    ~40, ->26
   58    58    > > RETURN                                                   !5
   59    59*     > RETURN                                                   null

End of function decompress

Function charat:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0iiFb
function name:  charAt
number of ops:  16
compiled vars:  !0 = $string, !1 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   61     2        INIT_FCALL                                               'mb_strlen'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        IS_SMALLER                                               !1, $2
          6      > JMPZ                                                     ~3, ->14
   62     7    >   INIT_FCALL                                               'mb_substr'
          8        SEND_VAR                                                 !0
          9        SEND_VAR                                                 !1
         10        SEND_VAL                                                 1
         11        DO_ICALL                                         $4      
         12      > RETURN                                                   $4
         13*       JMP                                                      ->15
   64    14    > > RETURN                                                   -1
   66    15*     > RETURN                                                   null

End of function charat

End of class LZW.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.83 ms | 1412 KiB | 21 Q