3v4l.org

run code in 500+ PHP versions simultaneously
<?php $crlf = chr(13) . chr(10); $cr = chr(13); $delimiter = '|'; $enclosure = '"'; //$escape = "\\"; $escape = "\0"; ini_set('auto_detect_line_endings', false); // 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); $rows = []; while (!$file->eof()) { $row = $file->fgetcsv($delimiter, $enclosure, $escape); 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 (str_replace($enclosure, '', implode($crlf, $lines)) !== implode($crlf, $rows)) { print_r("SplFileObject::fgetcsv() error! Expected:\n"); print_r($lines); print_r("Parsed as:\n"); print_r($rows); } else { print_r("SplFileObject::fgetcsv() passed."); } unset($file); // via fopen print_r("\n\n\n"); $file = fopen($filePath, 'r'); $rows = []; while (!feof($file)) { $row = fgetcsv($file, 0, $delimiter, $enclosure, $escape); if ($row === null) { print_r("NULL result found\n"); } else { $rows[] = implode($delimiter, $row); } } if (str_replace($enclosure, '', implode($crlf, $lines)) !== implode($crlf, $rows)) { print_r("fgetcsv() error! Expected:\n"); print_r($lines); print_r("Parsed as:\n"); print_r($rows); } else { print_r("fgetcsv() passed."); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 61, Position 2 = 42
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 80
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 83
Branch analysis from position: 83
1 jumps found. (Code = 42) Position 1 = 111
Branch analysis from position: 111
2 jumps found. (Code = 44) Position 1 = 116, Position 2 = 94
Branch analysis from position: 116
2 jumps found. (Code = 43) Position 1 = 122, Position 2 = 135
Branch analysis from position: 122
1 jumps found. (Code = 42) Position 1 = 138
Branch analysis from position: 138
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 135
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 94
2 jumps found. (Code = 43) Position 1 = 104, Position 2 = 108
Branch analysis from position: 104
1 jumps found. (Code = 42) Position 1 = 111
Branch analysis from position: 111
Branch analysis from position: 108
2 jumps found. (Code = 44) Position 1 = 116, Position 2 = 94
Branch analysis from position: 116
Branch analysis from position: 94
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 111
Branch analysis from position: 111
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 54
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 61, Position 2 = 42
Branch analysis from position: 61
Branch analysis from position: 42
filename:       /in/UOIED
function name:  (null)
number of ops:  139
compiled vars:  !0 = $crlf, !1 = $cr, !2 = $delimiter, !3 = $enclosure, !4 = $escape, !5 = $lines, !6 = $csv, !7 = $filePath, !8 = $file, !9 = $rows, !10 = $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'
    7     3        ASSIGN                                                       !3, '%22'
    9     4        ASSIGN                                                       !4, '%00'
   11     5        INIT_FCALL                                                   'ini_set'
          6        SEND_VAL                                                     'auto_detect_line_endings'
          7        SEND_VAL                                                     <false>
          8        DO_ICALL                                                     
   16     9        INIT_ARRAY                                           ~17     'A'
   17    10        ADD_ARRAY_ELEMENT                                    ~17     'a'
   18    11        ADD_ARRAY_ELEMENT                                    ~17     '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'
   19    12        ADD_ARRAY_ELEMENT                                    ~17     '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'
   20    13        CONCAT                                               ~18     '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
   21    14        CONCAT                                               ~19     ~18, '%22%7CMISSING+LINE+CONTENTS%7C'
         15        ADD_ARRAY_ELEMENT                                    ~17     ~19
   22    16        ADD_ARRAY_ELEMENT                                    ~17     'FF_FFFF%7CFF_1'
   23    17        ADD_ARRAY_ELEMENT                                    ~17     '%7C1'
   15    18        ASSIGN                                                       !5, ~17
   26    19        FRAMELESS_ICALL_2                implode             ~21     !0, !5
         20        ASSIGN                                                       !6, ~21
   28    21        INIT_FCALL                                                   'tempnam'
         22        INIT_FCALL                                                   'sys_get_temp_dir'
         23        DO_ICALL                                             $23     
         24        SEND_VAR                                                     $23
         25        SEND_VAL                                                     'csv'
         26        DO_ICALL                                             $24     
         27        ASSIGN                                                       !7, $24
   29    28        INIT_FCALL                                                   'file_put_contents'
         29        SEND_VAR                                                     !7
         30        SEND_VAR                                                     !6
         31        DO_ICALL                                                     
   31    32        NEW                                                  $27     'SplFileObject'
         33        SEND_VAR_EX                                                  !7
         34        SEND_VAL_EX                                                  'r'
         35        DO_FCALL                                          0          
         36        ASSIGN                                                       !8, $27
   32    37        INIT_METHOD_CALL                                             !8, 'setFlags'
         38        SEND_VAL_EX                                                  13
         39        DO_FCALL                                          0          
   35    40        ASSIGN                                                       !9, <array>
   36    41      > JMP                                                          ->57
   37    42    >   INIT_METHOD_CALL                                             !8, 'fgetcsv'
         43        SEND_VAR_EX                                                  !2
         44        SEND_VAR_EX                                                  !3
         45        SEND_VAR_EX                                                  !4
         46        DO_FCALL                                          0  $32     
         47        ASSIGN                                                       !10, $32
   39    48        TYPE_CHECK                                        2          !10
         49      > JMPZ                                                         ~34, ->54
   40    50    >   INIT_FCALL                                                   'print_r'
         51        SEND_VAL                                                     'NULL+result+found+though+%60SplFileObject%3A%3ASKIP_EMPTY+%7C+SplFileObject%3A%3ADROP_NEW_LINE%60+flags+set.%0A'
         52        DO_ICALL                                                     
   39    53      > JMP                                                          ->57
   42    54    >   FRAMELESS_ICALL_2                implode             ~37     !2, !10
         55        ASSIGN_DIM                                                   !9
         56        OP_DATA                                                      ~37
   36    57    >   INIT_METHOD_CALL                                             !8, 'eof'
         58        DO_FCALL                                          0  $38     
         59        BOOL_NOT                                             ~39     $38
         60      > JMPNZ                                                        ~39, ->42
   46    61    >   FRAMELESS_ICALL_2                implode             ~40     !0, !5
         62        FRAMELESS_ICALL_3                str_replace         ~41     !3, ''
         63        OP_DATA                                                      ~40
         64        FRAMELESS_ICALL_2                implode             ~42     !0, !9
         65        IS_NOT_IDENTICAL                                             ~41, ~42
         66      > JMPZ                                                         ~43, ->80
   47    67    >   INIT_FCALL                                                   'print_r'
         68        SEND_VAL                                                     'SplFileObject%3A%3Afgetcsv%28%29+error%21+Expected%3A%0A'
         69        DO_ICALL                                                     
   48    70        INIT_FCALL                                                   'print_r'
         71        SEND_VAR                                                     !5
         72        DO_ICALL                                                     
   49    73        INIT_FCALL                                                   'print_r'
         74        SEND_VAL                                                     'Parsed+as%3A%0A'
         75        DO_ICALL                                                     
   50    76        INIT_FCALL                                                   'print_r'
         77        SEND_VAR                                                     !9
         78        DO_ICALL                                                     
   46    79      > JMP                                                          ->83
   52    80    >   INIT_FCALL                                                   'print_r'
         81        SEND_VAL                                                     'SplFileObject%3A%3Afgetcsv%28%29+passed.'
         82        DO_ICALL                                                     
   55    83    >   UNSET_CV                                                     !8
   59    84        INIT_FCALL                                                   'print_r'
         85        SEND_VAL                                                     '%0A%0A%0A'
         86        DO_ICALL                                                     
   61    87        INIT_FCALL                                                   'fopen'
         88        SEND_VAR                                                     !7
         89        SEND_VAL                                                     'r'
         90        DO_ICALL                                             $50     
         91        ASSIGN                                                       !8, $50
   64    92        ASSIGN                                                       !9, <array>
   65    93      > JMP                                                          ->111
   66    94    >   INIT_FCALL                                                   'fgetcsv'
         95        SEND_VAR                                                     !8
         96        SEND_VAL                                                     0
         97        SEND_VAR                                                     !2
         98        SEND_VAR                                                     !3
         99        SEND_VAR                                                     !4
        100        DO_ICALL                                             $53     
        101        ASSIGN                                                       !10, $53
   68   102        TYPE_CHECK                                        2          !10
        103      > JMPZ                                                         ~55, ->108
   69   104    >   INIT_FCALL                                                   'print_r'
        105        SEND_VAL                                                     'NULL+result+found%0A'
        106        DO_ICALL                                                     
   68   107      > JMP                                                          ->111
   71   108    >   FRAMELESS_ICALL_2                implode             ~58     !2, !10
        109        ASSIGN_DIM                                                   !9
        110        OP_DATA                                                      ~58
   65   111    >   INIT_FCALL                                                   'feof'
        112        SEND_VAR                                                     !8
        113        DO_ICALL                                             $59     
        114        BOOL_NOT                                             ~60     $59
        115      > JMPNZ                                                        ~60, ->94
   75   116    >   FRAMELESS_ICALL_2                implode             ~61     !0, !5
        117        FRAMELESS_ICALL_3                str_replace         ~62     !3, ''
        118        OP_DATA                                                      ~61
        119        FRAMELESS_ICALL_2                implode             ~63     !0, !9
        120        IS_NOT_IDENTICAL                                             ~62, ~63
        121      > JMPZ                                                         ~64, ->135
   76   122    >   INIT_FCALL                                                   'print_r'
        123        SEND_VAL                                                     'fgetcsv%28%29+error%21+Expected%3A%0A'
        124        DO_ICALL                                                     
   77   125        INIT_FCALL                                                   'print_r'
        126        SEND_VAR                                                     !5
        127        DO_ICALL                                                     
   78   128        INIT_FCALL                                                   'print_r'
        129        SEND_VAL                                                     'Parsed+as%3A%0A'
        130        DO_ICALL                                                     
   79   131        INIT_FCALL                                                   'print_r'
        132        SEND_VAR                                                     !9
        133        DO_ICALL                                                     
   75   134      > JMP                                                          ->138
   81   135    >   INIT_FCALL                                                   'print_r'
        136        SEND_VAL                                                     'fgetcsv%28%29+passed.'
        137        DO_ICALL                                                     
   82   138    > > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
204.1 ms | 1544 KiB | 16 Q