3v4l.org

run code in 500+ 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 | SplFileObject::READ_CSV); //ini_set('auto_detect_line_endings', true); $rows = []; while (!$file->eof()) { $row = $file->fgetcsv($delimiter, '"', "\0"); 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 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 36
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 72
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 72
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 48
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 36
Branch analysis from position: 55
Branch analysis from position: 36
filename:       /in/ga46S
function name:  (null)
number of ops:  76
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%22%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, '%22%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        FRAMELESS_ICALL_2                implode             ~16     !0, !3
         14        ASSIGN                                                       !4, ~16
   22    15        INIT_FCALL                                                   'tempnam'
         16        INIT_FCALL                                                   'sys_get_temp_dir'
         17        DO_ICALL                                             $18     
         18        SEND_VAR                                                     $18
         19        SEND_VAL                                                     'csv'
         20        DO_ICALL                                             $19     
         21        ASSIGN                                                       !5, $19
   23    22        INIT_FCALL                                                   'file_put_contents'
         23        SEND_VAR                                                     !5
         24        SEND_VAR                                                     !4
         25        DO_ICALL                                                     
   25    26        NEW                                                  $22     'SplFileObject'
         27        SEND_VAR_EX                                                  !5
         28        SEND_VAL_EX                                                  'r'
         29        DO_FCALL                                          0          
         30        ASSIGN                                                       !6, $22
   26    31        INIT_METHOD_CALL                                             !6, 'setFlags'
         32        SEND_VAL_EX                                                  13
         33        DO_FCALL                                          0          
   31    34        ASSIGN                                                       !7, <array>
   32    35      > JMP                                                          ->51
   33    36    >   INIT_METHOD_CALL                                             !6, 'fgetcsv'
         37        SEND_VAR_EX                                                  !2
         38        SEND_VAL_EX                                                  '%22'
         39        SEND_VAL_EX                                                  '%00'
         40        DO_FCALL                                          0  $27     
         41        ASSIGN                                                       !8, $27
   35    42        TYPE_CHECK                                        2          !8
         43      > JMPZ                                                         ~29, ->48
   36    44    >   INIT_FCALL                                                   'print_r'
         45        SEND_VAL                                                     'NULL+result+found+though+%60SplFileObject%3A%3ASKIP_EMPTY+%7C+SplFileObject%3A%3ADROP_NEW_LINE%60+flags+set.%0A'
         46        DO_ICALL                                                     
   35    47      > JMP                                                          ->51
   38    48    >   FRAMELESS_ICALL_2                implode             ~32     !2, !8
         49        ASSIGN_DIM                                                   !7
         50        OP_DATA                                                      ~32
   32    51    >   INIT_METHOD_CALL                                             !6, 'eof'
         52        DO_FCALL                                          0  $33     
         53        BOOL_NOT                                             ~34     $33
         54      > JMPNZ                                                        ~34, ->36
   42    55    >   FRAMELESS_ICALL_2                implode             ~35     !0, !3
         56        FRAMELESS_ICALL_2                implode             ~36     !0, !7
         57        IS_NOT_IDENTICAL                                             ~35, ~36
         58      > JMPZ                                                         ~37, ->72
   43    59    >   INIT_FCALL                                                   'print_r'
         60        SEND_VAL                                                     'Error%21+Expected%3A%0A'
         61        DO_ICALL                                                     
   44    62        INIT_FCALL                                                   'print_r'
         63        SEND_VAR                                                     !3
         64        DO_ICALL                                                     
   45    65        INIT_FCALL                                                   'print_r'
         66        SEND_VAL                                                     'Parsed+as%3A%0A'
         67        DO_ICALL                                                     
   46    68        INIT_FCALL                                                   'print_r'
         69        SEND_VAR                                                     !7
         70        DO_ICALL                                                     
   42    71      > JMP                                                          ->75
   48    72    >   INIT_FCALL                                                   'print_r'
         73        SEND_VAL                                                     'Passed.'
         74        DO_ICALL                                                     
   49    75    > > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
164.23 ms | 1802 KiB | 12 Q