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