1--TEST--
2Test fgetcsv() : usage variations - with default enclosure, blank line
3--FILE--
4<?php
5/*
6  Testing fgetcsv() to read a file containing blank line when provided with
7  default enclosure argument
8*/
9
10echo "*** Testing fgetcsv() : with default enclosure, blank line ***\n";
11
12$filename = __DIR__ . '/fgetcsv_variation21.tmp';
13@unlink($filename);
14
15$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t",
16                     "a+", "a+b", "a+t",
17                     "w+", "w+b", "w+t",
18                     "x+", "x+b", "x+t");
19
20$loop_counter = 1;
21  for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
22    // create the file and add the content with has csv fields
23    if ( strstr($file_modes[$mode_counter], "r") ) {
24      $file_handle = fopen($filename, "w");
25    } else {
26      $file_handle = fopen($filename, $file_modes[$mode_counter] );
27    }
28    if ( !$file_handle ) {
29      echo "Error: failed to create file $filename!\n";
30      exit();
31    }
32    // write a blank line
33    fwrite($file_handle, "\n"); // blank line
34
35    // close the file if the mode to be used is read mode  and re-open using read mode
36    // else rewind the file pointer to beginning of the file
37    if ( strstr($file_modes[$mode_counter], "r" ) ) {
38      fclose($file_handle);
39      $file_handle = fopen($filename, $file_modes[$mode_counter]);
40    } else {
41      // rewind the file pointer to bof
42      rewind($file_handle);
43    }
44
45    echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n";
46
47    // call fgetcsv() to parse csv fields
48
49    // read the line which is a blank line to see the working of fgetcsv
50    $fp_pos = ftell($file_handle);
51    var_dump( fgetcsv($file_handle, 1024, '+') );
52    // check the file pointer position and if eof
53    var_dump( ftell($file_handle) );
54    var_dump( feof($file_handle) );
55
56    // close the file
57    fclose($file_handle);
58    //delete file
59    unlink($filename);
60  } //end of mode loop
61
62echo "Done\n";
63?>
64--EXPECT--
65*** Testing fgetcsv() : with default enclosure, blank line ***
66
67-- Testing fgetcsv() with file opened using r mode --
68array(1) {
69  [0]=>
70  NULL
71}
72int(1)
73bool(false)
74
75-- Testing fgetcsv() with file opened using rb mode --
76array(1) {
77  [0]=>
78  NULL
79}
80int(1)
81bool(false)
82
83-- Testing fgetcsv() with file opened using rt mode --
84array(1) {
85  [0]=>
86  NULL
87}
88int(1)
89bool(false)
90
91-- Testing fgetcsv() with file opened using r+ mode --
92array(1) {
93  [0]=>
94  NULL
95}
96int(1)
97bool(false)
98
99-- Testing fgetcsv() with file opened using r+b mode --
100array(1) {
101  [0]=>
102  NULL
103}
104int(1)
105bool(false)
106
107-- Testing fgetcsv() with file opened using r+t mode --
108array(1) {
109  [0]=>
110  NULL
111}
112int(1)
113bool(false)
114
115-- Testing fgetcsv() with file opened using a+ mode --
116array(1) {
117  [0]=>
118  NULL
119}
120int(1)
121bool(false)
122
123-- Testing fgetcsv() with file opened using a+b mode --
124array(1) {
125  [0]=>
126  NULL
127}
128int(1)
129bool(false)
130
131-- Testing fgetcsv() with file opened using a+t mode --
132array(1) {
133  [0]=>
134  NULL
135}
136int(1)
137bool(false)
138
139-- Testing fgetcsv() with file opened using w+ mode --
140array(1) {
141  [0]=>
142  NULL
143}
144int(1)
145bool(false)
146
147-- Testing fgetcsv() with file opened using w+b mode --
148array(1) {
149  [0]=>
150  NULL
151}
152int(1)
153bool(false)
154
155-- Testing fgetcsv() with file opened using w+t mode --
156array(1) {
157  [0]=>
158  NULL
159}
160int(1)
161bool(false)
162
163-- Testing fgetcsv() with file opened using x+ mode --
164array(1) {
165  [0]=>
166  NULL
167}
168int(1)
169bool(false)
170
171-- Testing fgetcsv() with file opened using x+b mode --
172array(1) {
173  [0]=>
174  NULL
175}
176int(1)
177bool(false)
178
179-- Testing fgetcsv() with file opened using x+t mode --
180array(1) {
181  [0]=>
182  NULL
183}
184int(1)
185bool(false)
186Done
187