Annotation of embedaddon/php/ext/standard/tests/file/fgetcsv_variation14.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test fgetcsv() : usage variations - reading the blank line
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() by reading a file containing a blank line */
11:
12: echo "*** Testing fgetcsv() : reading the blank line ***\n";
13:
14:
15: $filename = dirname(__FILE__) . '/fgetcsv_variation14.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 a blank line
36: fwrite($file_handle, "\n"); // blank line
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 begining 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: // call fgetcsv() to parse csv fields
51:
52: // read the next line which is a blank line to see the working of fgetcsv
53: $fp_pos = ftell($file_handle);
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: // read again to struck EOF
59: var_dump( fgetcsv($file_handle, 1024) );
60: // check the file pointer position and if eof
61: var_dump( ftell($file_handle) );
62: var_dump( feof($file_handle) );
63:
64: // close the file
65: fclose($file_handle);
66: //delete file
67: unlink($filename);
68: } //end of mode loop
69:
70: echo "Done\n";
71: ?>
72: --EXPECT--
73: *** Testing fgetcsv() : reading the blank line ***
74:
75: -- Testing fgetcsv() with file opened using r mode --
76: array(1) {
77: [0]=>
78: NULL
79: }
80: int(1)
81: bool(false)
82: bool(false)
83: int(1)
84: bool(true)
85:
86: -- Testing fgetcsv() with file opened using rb mode --
87: array(1) {
88: [0]=>
89: NULL
90: }
91: int(1)
92: bool(false)
93: bool(false)
94: int(1)
95: bool(true)
96:
97: -- Testing fgetcsv() with file opened using rt mode --
98: array(1) {
99: [0]=>
100: NULL
101: }
102: int(1)
103: bool(false)
104: bool(false)
105: int(1)
106: bool(true)
107:
108: -- Testing fgetcsv() with file opened using r+ mode --
109: array(1) {
110: [0]=>
111: NULL
112: }
113: int(1)
114: bool(false)
115: bool(false)
116: int(1)
117: bool(true)
118:
119: -- Testing fgetcsv() with file opened using r+b mode --
120: array(1) {
121: [0]=>
122: NULL
123: }
124: int(1)
125: bool(false)
126: bool(false)
127: int(1)
128: bool(true)
129:
130: -- Testing fgetcsv() with file opened using r+t mode --
131: array(1) {
132: [0]=>
133: NULL
134: }
135: int(1)
136: bool(false)
137: bool(false)
138: int(1)
139: bool(true)
140:
141: -- Testing fgetcsv() with file opened using a+ mode --
142: array(1) {
143: [0]=>
144: NULL
145: }
146: int(1)
147: bool(false)
148: bool(false)
149: int(1)
150: bool(true)
151:
152: -- Testing fgetcsv() with file opened using a+b mode --
153: array(1) {
154: [0]=>
155: NULL
156: }
157: int(1)
158: bool(false)
159: bool(false)
160: int(1)
161: bool(true)
162:
163: -- Testing fgetcsv() with file opened using a+t mode --
164: array(1) {
165: [0]=>
166: NULL
167: }
168: int(1)
169: bool(false)
170: bool(false)
171: int(1)
172: bool(true)
173:
174: -- Testing fgetcsv() with file opened using w+ mode --
175: array(1) {
176: [0]=>
177: NULL
178: }
179: int(1)
180: bool(false)
181: bool(false)
182: int(1)
183: bool(true)
184:
185: -- Testing fgetcsv() with file opened using w+b mode --
186: array(1) {
187: [0]=>
188: NULL
189: }
190: int(1)
191: bool(false)
192: bool(false)
193: int(1)
194: bool(true)
195:
196: -- Testing fgetcsv() with file opened using w+t mode --
197: array(1) {
198: [0]=>
199: NULL
200: }
201: int(1)
202: bool(false)
203: bool(false)
204: int(1)
205: bool(true)
206:
207: -- Testing fgetcsv() with file opened using x+ mode --
208: array(1) {
209: [0]=>
210: NULL
211: }
212: int(1)
213: bool(false)
214: bool(false)
215: int(1)
216: bool(true)
217:
218: -- Testing fgetcsv() with file opened using x+b mode --
219: array(1) {
220: [0]=>
221: NULL
222: }
223: int(1)
224: bool(false)
225: bool(false)
226: int(1)
227: bool(true)
228:
229: -- Testing fgetcsv() with file opened using x+t mode --
230: array(1) {
231: [0]=>
232: NULL
233: }
234: int(1)
235: bool(false)
236: bool(false)
237: int(1)
238: bool(true)
239: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>