3v4l.org

run code in 300+ PHP versions simultaneously
<?php $segments = [1,2,3,4,5,6,7,8,9,1]; $box_size = 4; $input = 'Loremipsumdolorsitametconsecteturadipiscingeli'; $output = []; function string_to_stream($string) { $in = fopen('php://memory','r+'); fwrite($in, $string); rewind($in); return $in; } $stream = string_to_stream($input); $left_over = ''; while (($segment = array_shift($segments)) !== null) { while (strlen($left_over) < $segment) { $left_over .= fread($stream, $box_size); } $output[] = substr($left_over, 0, $segment); $left_over = substr($left_over, $segment); } if (implode('', $output) === $input) { echo 'Algorithm Correct !' . PHP_EOL . PHP_EOL; } foreach ($output as $v) { echo $v . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 10
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 44
Branch analysis from position: 43
2 jumps found. (Code = 77) Position 1 = 45, Position 2 = 49
Branch analysis from position: 45
2 jumps found. (Code = 78) Position 1 = 46, Position 2 = 49
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
Branch analysis from position: 44
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 11
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 10
Branch analysis from position: 37
Branch analysis from position: 10
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 11
Branch analysis from position: 19
Branch analysis from position: 11
filename:       /in/HIehL
function name:  (null)
number of ops:  51
compiled vars:  !0 = $segments, !1 = $box_size, !2 = $input, !3 = $output, !4 = $stream, !5 = $left_over, !6 = $segment, !7 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, 4
    6     2        ASSIGN                                                   !2, 'Loremipsumdolorsitametconsecteturadipiscingeli'
    7     3        ASSIGN                                                   !3, <array>
   15     4        INIT_FCALL                                               'string_to_stream'
          5        SEND_VAR                                                 !2
          6        DO_FCALL                                      0  $12     
          7        ASSIGN                                                   !4, $12
   17     8        ASSIGN                                                   !5, ''
   18     9      > JMP                                                      ->31
   19    10    > > JMP                                                      ->16
   20    11    >   INIT_FCALL                                               'fread'
         12        SEND_VAR                                                 !4
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $15     
         15        ASSIGN_OP                                     8          !5, $15
   19    16    >   STRLEN                                           ~17     !5
         17        IS_SMALLER                                               ~17, !6
         18      > JMPNZ                                                    ~18, ->11
   22    19    >   INIT_FCALL                                               'substr'
         20        SEND_VAR                                                 !5
         21        SEND_VAL                                                 0
         22        SEND_VAR                                                 !6
         23        DO_ICALL                                         $20     
         24        ASSIGN_DIM                                               !3
         25        OP_DATA                                                  $20
   23    26        INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !5
         28        SEND_VAR                                                 !6
         29        DO_ICALL                                         $21     
         30        ASSIGN                                                   !5, $21
   18    31    >   INIT_FCALL                                               'array_shift'
         32        SEND_REF                                                 !0
         33        DO_ICALL                                         $23     
         34        ASSIGN                                           ~24     !6, $23
         35        TYPE_CHECK                                  1020          ~24
         36      > JMPNZ                                                    ~25, ->10
   26    37    >   INIT_FCALL                                               'implode'
         38        SEND_VAL                                                 ''
         39        SEND_VAR                                                 !3
         40        DO_ICALL                                         $26     
         41        IS_IDENTICAL                                             !2, $26
         42      > JMPZ                                                     ~27, ->44
   27    43    >   ECHO                                                     'Algorithm+Correct+%21%0A%0A'
   30    44    > > FE_RESET_R                                       $28     !3, ->49
         45    > > FE_FETCH_R                                               $28, !7, ->49
   31    46    >   CONCAT                                           ~29     !7, '%0A'
         47        ECHO                                                     ~29
   30    48      > JMP                                                      ->45
         49    >   FE_FREE                                                  $28
   32    50      > RETURN                                                   1

Function string_to_stream:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HIehL
function name:  string_to_stream
number of ops:  15
compiled vars:  !0 = $string, !1 = $in
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        INIT_FCALL                                               'fopen'
          2        SEND_VAL                                                 'php%3A%2F%2Fmemory'
          3        SEND_VAL                                                 'r%2B'
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !1, $2
   11     6        INIT_FCALL                                               'fwrite'
          7        SEND_VAR                                                 !1
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                                 
   12    10        INIT_FCALL                                               'rewind'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                                 
   13    13      > RETURN                                                   !1
   14    14*     > RETURN                                                   null

End of function string_to_stream

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.17 ms | 1403 KiB | 28 Q