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