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