3v4l.org

run code in 300+ 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 = 63
Branch analysis from position: 63
2 jumps found. (Code = 44) Position 1 = 67, Position 2 = 45
Branch analysis from position: 67
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 95
Branch analysis from position: 82
1 jumps found. (Code = 42) Position 1 = 98
Branch analysis from position: 98
1 jumps found. (Code = 42) Position 1 = 129
Branch analysis from position: 129
2 jumps found. (Code = 44) Position 1 = 134, Position 2 = 109
Branch analysis from position: 134
2 jumps found. (Code = 43) Position 1 = 149, Position 2 = 162
Branch analysis from position: 149
1 jumps found. (Code = 42) Position 1 = 165
Branch analysis from position: 165
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 162
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 109
2 jumps found. (Code = 43) Position 1 = 119, Position 2 = 123
Branch analysis from position: 119
1 jumps found. (Code = 42) Position 1 = 129
Branch analysis from position: 129
Branch analysis from position: 123
2 jumps found. (Code = 44) Position 1 = 134, Position 2 = 109
Branch analysis from position: 134
Branch analysis from position: 109
Branch analysis from position: 95
1 jumps found. (Code = 42) Position 1 = 129
Branch analysis from position: 129
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 57
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 67, Position 2 = 45
Branch analysis from position: 67
Branch analysis from position: 45
filename:       /in/UOIED
function name:  (null)
number of ops:  166
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 >   QM_ASSIGN                                                !0
   4     1        QM_ASSIGN                                                !1
   6     2        QM_ASSIGN                                                !2
   7     3        QM_ASSIGN                                                !3
   9     4        QM_ASSIGN                                                !4
  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'
        18        QM_ASSIGN                                                !5
  26    19        INIT_FCALL                                               'implode'
        20        SEND_VAR                                                 !0
        21        SEND_VAR                                                 !5
        22        DO_ICALL                                         $21     
        23        QM_ASSIGN                                                !6
  28    24        INIT_FCALL                                               'tempnam'
        25        INIT_FCALL                                               'sys_get_temp_dir'
        26        DO_ICALL                                         $23     
        27        SEND_VAR                                                 $23
        28        SEND_VAL                                                 'csv'
        29        DO_ICALL                                         $24     
        30        QM_ASSIGN                                                !7
  29    31        INIT_FCALL                                               'file_put_contents'
        32        SEND_VAR                                                 !7
        33        SEND_VAR                                                 !6
        34        DO_ICALL                                                 
  31    35        NEW                                              $27     :278
        36        SEND_VAR_EX                                              !7
        37        SEND_VAL_EX                                              'r'
        38        DO_FCALL                                      0          
        39        QM_ASSIGN                                                !8
  32    40        INIT_METHOD_CALL                                         !8, 'setFlags'
        41        SEND_VAL_EX                                              13
        42        DO_FCALL                                      0          
  35    43        QM_ASSIGN                                                !9
  36    44      > JMP                                                      ->63
  37    45    >   INIT_METHOD_CALL                                         !8, 'fgetcsv'
        46        SEND_VAR_EX                                              !2
        47        SEND_VAR_EX                                              !3
        48        SEND_VAR_EX                                              !4
        49        DO_FCALL                                      0  $32     
        50        QM_ASSIGN                                                !10
  39    51        IS_NOT_IDENTICAL                                 ~34     !10, null
        52      > JMPZ                                                     ~34, ->57
  40    53    >   INIT_FCALL                                               'print_r'
        54        SEND_VAL                                                 'NULL+result+found+though+%60SplFileObject%3A%3ASKIP_EMPTY+%7C+SplFileObject%3A%3ADROP_NEW_LINE%60+flags+set.%0A'
        55        DO_ICALL                                                 
        56      > JMP                                                      ->63
  42    57    >   INIT_FCALL                                               'implode'
        58        SEND_VAR                                                 !2
        59        SEND_VAR                                                 !10
        60        DO_ICALL                                         $37     
        61        ASSIGN_ADD                                    0          !9
        62        OP_DATA                                                  $37
  36    63    >   INIT_METHOD_CALL                                         !8, 'eof'
        64        DO_FCALL                                      0  $38     
        65        BOOL_XOR                                         ~39     $38
        66      > JMPNZ                                                    ~39, ->45
  46    67    >   INIT_FCALL                                               'str_replace'
        68        SEND_VAR                                                 !3
        69        SEND_VAL                                                 ''
        70        INIT_FCALL                                               'implode'
        71        SEND_VAR                                                 !0
        72        SEND_VAR                                                 !5
        73        DO_ICALL                                         $40     
        74        SEND_VAR                                                 $40
        75        DO_ICALL                                         $41     
        76        INIT_FCALL                                               'implode'
        77        SEND_VAR                                                 !0
        78        SEND_VAR                                                 !9
        79        DO_ICALL                                         $42     
        80        IS_EQUAL                                         ~43     $41, $42
        81      > JMPZ                                                     ~43, ->95
  47    82    >   INIT_FCALL                                               'print_r'
        83        SEND_VAL                                                 'SplFileObject%3A%3Afgetcsv%28%29+error%21+Expected%3A%0A'
        84        DO_ICALL                                                 
  48    85        INIT_FCALL                                               'print_r'
        86        SEND_VAR                                                 !5
        87        DO_ICALL                                                 
  49    88        INIT_FCALL                                               'print_r'
        89        SEND_VAL                                                 'Parsed+as%3A%0A'
        90        DO_ICALL                                                 
  50    91        INIT_FCALL                                               'print_r'
        92        SEND_VAR                                                 !9
        93        DO_ICALL                                                 
        94      > JMP                                                      ->98
  52    95    >   INIT_FCALL                                               'print_r'
        96        SEND_VAL                                                 'SplFileObject%3A%3Afgetcsv%28%29+passed.'
        97        DO_ICALL                                                 
  55    98    >   DECLARE_LAMBDA_FUNCTION                                  !8
  59    99        INIT_FCALL                                               'print_r'
       100        SEND_VAL                                                 '%0A%0A%0A'
       101        DO_ICALL                                                 
  61   102        INIT_FCALL                                               'fopen'
       103        SEND_VAR                                                 !7
       104        SEND_VAL                                                 'r'
       105        DO_ICALL                                         $50     
       106        QM_ASSIGN                                                !8
  64   107        QM_ASSIGN                                                !9
  65   108      > JMP                                                      ->129
  66   109    >   INIT_FCALL                                               'fgetcsv'
       110        SEND_VAR                                                 !8
       111        SEND_VAL                                                 0
       112        SEND_VAR                                                 !2
       113        SEND_VAR                                                 !3
       114        SEND_VAR                                                 !4
       115        DO_ICALL                                         $53     
       116        QM_ASSIGN                                                !10
  68   117        IS_NOT_IDENTICAL                                 ~55     !10, null
       118      > JMPZ                                                     ~55, ->123
  69   119    >   INIT_FCALL                                               'print_r'
       120        SEND_VAL                                                 'NULL+result+found%0A'
       121        DO_ICALL                                                 
       122      > JMP                                                      ->129
  71   123    >   INIT_FCALL                                               'implode'
       124        SEND_VAR                                                 !2
       125        SEND_VAR                                                 !10
       126        DO_ICALL                                         $58     
       127        ASSIGN_ADD                                    0          !9
       128        OP_DATA                                                  $58
  65   129    >   INIT_FCALL                                               'feof'
       130        SEND_VAR                                                 !8
       131        DO_ICALL                                         $59     
       132        BOOL_XOR                                         ~60     $59
       133      > JMPNZ                                                    ~60, ->109
  75   134    >   INIT_FCALL                                               'str_replace'
       135        SEND_VAR                                                 !3
       136        SEND_VAL                                                 ''
       137        INIT_FCALL                                               'implode'
       138        SEND_VAR                                                 !0
       139        SEND_VAR                                                 !5
       140        DO_ICALL                                         $61     
       141        SEND_VAR                                                 $61
       142        DO_ICALL                                         $62     
       143        INIT_FCALL                                               'implode'
       144        SEND_VAR                                                 !0
       145        SEND_VAR                                                 !9
       146        DO_ICALL                                         $63     
       147        IS_EQUAL                                         ~64     $62, $63
       148      > JMPZ                                                     ~64, ->162
  76   149    >   INIT_FCALL                                               'print_r'
       150        SEND_VAL                                                 'fgetcsv%28%29+error%21+Expected%3A%0A'
       151        DO_ICALL                                                 
  77   152        INIT_FCALL                                               'print_r'
       153        SEND_VAR                                                 !5
       154        DO_ICALL                                                 
  78   155        INIT_FCALL                                               'print_r'
       156        SEND_VAL                                                 'Parsed+as%3A%0A'
       157        DO_ICALL                                                 
  79   158        INIT_FCALL                                               'print_r'
       159        SEND_VAR                                                 !9
       160        DO_ICALL                                                 
       161      > JMP                                                      ->165
  81   162    >   INIT_FCALL                                               'print_r'
       163        SEND_VAL                                                 'fgetcsv%28%29+passed.'
       164        DO_ICALL                                                 
  82   165    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
15.43 ms | 428 KiB | 7 Q