3v4l.org

run code in 300+ PHP versions simultaneously
<?php $crlf = chr(13) . chr(10); $cr = chr(13); $delimiter = '|'; // 7 rows, 5th row has CR linebreak inside $lines = [ 'A', 'a', 'C15|C18|C21|C36|C42|C45|C48|C51|C54|C60|C63|C66|C69|C72|C75|C81|C84|C90|C93|C96|C99|C102|C105|C108|C111', '02-DEC-19|02-DEC-19|707403|GUEST|||PPPPPP||||||RR||||RRSSIAN||FFFF|||||+1111-11-11-111|', '02-DEC-19|02-DEC-19|707404|GUEST|SDDDDD|ВВВВВВВВВВВВ|PPPPPP|СССССС|ПППППП||01.01.1111|M|RR|ППППП|ПППППППП кккк' . $cr . '|MISSING LINE CONTENTS|', 'FF_FFFF|FF_1', '|1', ]; $csv = implode($crlf, $lines); $filePath = tempnam(sys_get_temp_dir(), 'csv'); file_put_contents($filePath, $csv); $file = new \SplFileObject($filePath, 'r'); $file->setFlags(SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE); ini_set('auto_detect_line_endings', true); $rows = []; while (!$file->eof()) { $row = $file->fgetcsv($delimiter, '"', '\\'); if ($row === null) { print_r("NULL result found though `SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE` flags set.\n"); } else { $rows[] = implode($delimiter, $row); } } if (implode($crlf, $lines) !== implode($crlf, $rows)) { print_r("Error! Expected:\n"); print_r($lines); print_r("Parsed as:\n"); print_r($rows); } else { print_r("Passed."); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 43
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 88
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 88
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 55
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 43
Branch analysis from position: 65
Branch analysis from position: 43
filename:       /in/k1B5Y
function name:  (null)
number of ops:  92
compiled vars:  !0 = $crlf, !1 = $cr, !2 = $delimiter, !3 = $lines, !4 = $csv, !5 = $filePath, !6 = $file, !7 = $rows, !8 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%0D%0A'
    4     1        ASSIGN                                                   !1, '%0D'
    6     2        ASSIGN                                                   !2, '%7C'
   10     3        INIT_ARRAY                                       ~12     'A'
   11     4        ADD_ARRAY_ELEMENT                                ~12     'a'
   12     5        ADD_ARRAY_ELEMENT                                ~12     'C15%7CC18%7CC21%7CC36%7CC42%7CC45%7CC48%7CC51%7CC54%7CC60%7CC63%7CC66%7CC69%7CC72%7CC75%7CC81%7CC84%7CC90%7CC93%7CC96%7CC99%7CC102%7CC105%7CC108%7CC111'
   13     6        ADD_ARRAY_ELEMENT                                ~12     '02-DEC-19%7C02-DEC-19%7C707403%7CGUEST%7C%7C%7CPPPPPP%7C%7C%7C%7C%7C%7CRR%7C%7C%7C%7CRRSSIAN%7C%7CFFFF%7C%7C%7C%7C%7C%2B1111-11-11-111%7C'
   14     7        CONCAT                                           ~13     '02-DEC-19%7C02-DEC-19%7C707404%7CGUEST%7CSDDDDD%7C%D0%92%D0%92%D0%92%D0%92%D0%92%D0%92%D0%92%D0%92%D0%92%D0%92%D0%92%D0%92%7CPPPPPP%7C%D0%A1%D0%A1%D0%A1%D0%A1%D0%A1%D0%A1%7C%D0%9F%D0%9F%D0%9F%D0%9F%D0%9F%D0%9F%7C%7C01.01.1111%7CM%7CRR%7C%D0%9F%D0%9F%D0%9F%D0%9F%D0%9F%7C%D0%9F%D0%9F%D0%9F%D0%9F%D0%9F%D0%9F%D0%9F%D0%9F+%D0%BA%D0%BA%D0%BA%D0%BA', !1
   15     8        CONCAT                                           ~14     ~13, '%7CMISSING+LINE+CONTENTS%7C'
          9        ADD_ARRAY_ELEMENT                                ~12     ~14
   16    10        ADD_ARRAY_ELEMENT                                ~12     'FF_FFFF%7CFF_1'
   17    11        ADD_ARRAY_ELEMENT                                ~12     '%7C1'
    9    12        ASSIGN                                                   !3, ~12
   20    13        INIT_FCALL                                               'implode'
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                         $16     
         17        ASSIGN                                                   !4, $16
   22    18        INIT_FCALL                                               'tempnam'
         19        INIT_FCALL                                               'sys_get_temp_dir'
         20        DO_ICALL                                         $18     
         21        SEND_VAR                                                 $18
         22        SEND_VAL                                                 'csv'
         23        DO_ICALL                                         $19     
         24        ASSIGN                                                   !5, $19
   23    25        INIT_FCALL                                               'file_put_contents'
         26        SEND_VAR                                                 !5
         27        SEND_VAR                                                 !4
         28        DO_ICALL                                                 
   25    29        NEW                                              $22     'SplFileObject'
         30        SEND_VAR_EX                                              !5
         31        SEND_VAL_EX                                              'r'
         32        DO_FCALL                                      0          
         33        ASSIGN                                                   !6, $22
   26    34        INIT_METHOD_CALL                                         !6, 'setFlags'
         35        SEND_VAL_EX                                              5
         36        DO_FCALL                                      0          
   28    37        INIT_FCALL                                               'ini_set'
         38        SEND_VAL                                                 'auto_detect_line_endings'
         39        SEND_VAL                                                 <true>
         40        DO_ICALL                                                 
   31    41        ASSIGN                                                   !7, <array>
   32    42      > JMP                                                      ->61
   33    43    >   INIT_METHOD_CALL                                         !6, 'fgetcsv'
         44        SEND_VAR_EX                                              !2
         45        SEND_VAL_EX                                              '%22'
         46        SEND_VAL_EX                                              '%5C'
         47        DO_FCALL                                      0  $28     
         48        ASSIGN                                                   !8, $28
   35    49        TYPE_CHECK                                    2          !8
         50      > JMPZ                                                     ~30, ->55
   36    51    >   INIT_FCALL                                               'print_r'
         52        SEND_VAL                                                 'NULL+result+found+though+%60SplFileObject%3A%3ASKIP_EMPTY+%7C+SplFileObject%3A%3ADROP_NEW_LINE%60+flags+set.%0A'
         53        DO_ICALL                                                 
         54      > JMP                                                      ->61
   38    55    >   INIT_FCALL                                               'implode'
         56        SEND_VAR                                                 !2
         57        SEND_VAR                                                 !8
         58        DO_ICALL                                         $33     
         59        ASSIGN_DIM                                               !7
         60        OP_DATA                                                  $33
   32    61    >   INIT_METHOD_CALL                                         !6, 'eof'
         62        DO_FCALL                                      0  $34     
         63        BOOL_NOT                                         ~35     $34
         64      > JMPNZ                                                    ~35, ->43
   42    65    >   INIT_FCALL                                               'implode'
         66        SEND_VAR                                                 !0
         67        SEND_VAR                                                 !3
         68        DO_ICALL                                         $36     
         69        INIT_FCALL                                               'implode'
         70        SEND_VAR                                                 !0
         71        SEND_VAR                                                 !7
         72        DO_ICALL                                         $37     
         73        IS_NOT_IDENTICAL                                         $36, $37
         74      > JMPZ                                                     ~38, ->88
   43    75    >   INIT_FCALL                                               'print_r'
         76        SEND_VAL                                                 'Error%21+Expected%3A%0A'
         77        DO_ICALL                                                 
   44    78        INIT_FCALL                                               'print_r'
         79        SEND_VAR                                                 !3
         80        DO_ICALL                                                 
   45    81        INIT_FCALL                                               'print_r'
         82        SEND_VAL                                                 'Parsed+as%3A%0A'
         83        DO_ICALL                                                 
   46    84        INIT_FCALL                                               'print_r'
         85        SEND_VAR                                                 !7
         86        DO_ICALL                                                 
         87      > JMP                                                      ->91
   48    88    >   INIT_FCALL                                               'print_r'
         89        SEND_VAL                                                 'Passed.'
         90        DO_ICALL                                                 
   49    91    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.73 ms | 1404 KiB | 25 Q