3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = <<<'EOD' 19018216307,Public,\,k]'=system1-system2,20230914143505.5,1-050000,No 32432151322,Public,blublabliblo,1324651651654.5,1-050000,No EOD; // change $filePath with the path of your file $filePath = 'data:text/plain;base64,' . base64_encode($str); if (false === $handle = fopen($filePath, 'r')) die("unable to open file $filePath"); $pattern = <<<'REGEX' ~(?nxx) (?# modifiers: - inline n: parenthesis act as a non-capturing group - inline xx: white-spaces are ignored even in character classes - global A: all the matches have to be contiguous ) # pattern ( (?!\A) , \K | \A ) # not at the start with a commas or at the start without [^ , \\ ]* ( \\ . [^ , \\ ]* )* # field content (all that isn't a comma nor # a backslash, except escaped characters) # final check ( \z (*:END) )? # define a marker if the end of the string is reached ~A REGEX; $result = []; // stream_get_line doesn't return the newline sequence (3rd parameter) // change it to \r\n or \r if needed, or use fgets and change \z with $ in the pattern while(false !== $line = stream_get_line($handle, 1024, "\n")) { if (preg_match_all($pattern, $line, $m) && isset($m['MARK'])) { $fields = array_map(fn($s) => strtr($s, ['\\\\' => '\\', '\\' => '']), $m[0]); $result[] = $fields; } else { die("unable to parse the following line:\n$line"); } } fclose($handle); print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 19
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 38
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 38
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 27
filename:       /in/M7tJP
function name:  (null)
number of ops:  56
compiled vars:  !0 = $str, !1 = $filePath, !2 = $handle, !3 = $pattern, !4 = $result, !5 = $line, !6 = $m, !7 = $fields
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '19018216307%2CPublic%2C%5C%2Ck%5D%27%3Dsystem1-system2%2C20230914143505.5%2C1-050000%2CNo%0A32432151322%2CPublic%2Cblublabliblo%2C1324651651654.5%2C1-050000%2CNo'
    9     1        INIT_FCALL                                               'base64_encode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $9      
          4        CONCAT                                           ~10     'data%3Atext%2Fplain%3Bbase64%2C', $9
          5        ASSIGN                                                   !1, ~10
   11     6        INIT_FCALL                                               'fopen'
          7        SEND_VAR                                                 !1
          8        SEND_VAL                                                 'r'
          9        DO_ICALL                                         $12     
         10        ASSIGN                                           ~13     !2, $12
         11        TYPE_CHECK                                    4          ~13
         12      > JMPZ                                                     ~14, ->16
   12    13    >   NOP                                                      
         14        FAST_CONCAT                                      ~15     'unable+to+open+file+', !1
         15      > EXIT                                                     ~15
   14    16    >   ASSIGN                                                   !3, '%7E%28%3Fnxx%29%0A++++%28%3F%23+modifiers%3A%0A++++++++-+inline+n%3A+parenthesis+act+as+a+non-capturing+group%0A++++++++-+inline+xx%3A+white-spaces+are+ignored+even+in+character+classes%0A++++++++-+global+A%3A+all+the+matches+have+to+be+contiguous%0A++++%29%0A%0A++++%23+pattern%0A++++%28+%28%3F%21%5CA%29+%2C+%5CK+%7C+%5CA+%29+%23+not+at+the+start+with+a+commas+or+at+the+start+without%0A++++%5B%5E+%2C+%5C%5C+%5D%2A+%28+%5C%5C+.+%5B%5E+%2C+%5C%5C+%5D%2A+%29%2A+%23+field+content+%28all+that+isn%27t+a+comma+nor%0A++++++++++++++++++++++++++++++++++++%23+a+backslash%2C+except+escaped+characters%29+%0A+++++++++++++++++++++++++++++++++++++++++++%0A++++%23+final+check%0A++++%28+%5Cz+%28%2A%3AEND%29+%29%3F+%23+define+a+marker+if+the+end+of+the+string+is+reached%0A%7EA'
   32    17        ASSIGN                                                   !4, <array>
   36    18      > JMP                                                      ->41
   37    19    >   INIT_FCALL                                               'preg_match_all'
         20        SEND_VAR                                                 !3
         21        SEND_VAR                                                 !5
         22        SEND_REF                                                 !6
         23        DO_ICALL                                         $18     
         24      > JMPZ_EX                                          ~19     $18, ->27
         25    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~20     !6, 'MARK'
         26        BOOL                                             ~19     ~20
         27    > > JMPZ                                                     ~19, ->38
   38    28    >   INIT_FCALL                                               'array_map'
         29        DECLARE_LAMBDA_FUNCTION                          ~21     [0]
         30        SEND_VAL                                                 ~21
         31        FETCH_DIM_R                                      ~22     !6, 0
         32        SEND_VAL                                                 ~22
         33        DO_ICALL                                         $23     
         34        ASSIGN                                                   !7, $23
   39    35        ASSIGN_DIM                                               !4
         36        OP_DATA                                                  !7
   37    37      > JMP                                                      ->41
   42    38    >   NOP                                                      
         39        FAST_CONCAT                                      ~26     'unable+to+parse+the+following+line%3A%0A', !5
         40      > EXIT                                                     ~26
   36    41    >   INIT_FCALL                                               'stream_get_line'
         42        SEND_VAR                                                 !2
         43        SEND_VAL                                                 1024
         44        SEND_VAL                                                 '%0A'
         45        DO_ICALL                                         $27     
         46        ASSIGN                                           ~28     !5, $27
         47        TYPE_CHECK                                  1018          ~28
         48      > JMPNZ                                                    ~29, ->19
   46    49    >   INIT_FCALL                                               'fclose'
         50        SEND_VAR                                                 !2
         51        DO_ICALL                                                 
   48    52        INIT_FCALL                                               'print_r'
         53        SEND_VAR                                                 !4
         54        DO_ICALL                                                 
         55      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M7tJP
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $s
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'strtr'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <array>
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
          6*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.91 ms | 1023 KiB | 21 Q