Annotation of embedaddon/php/ext/standard/tests/file/fgetcsv_variation13.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test 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:
13: echo "*** 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
1.1.1.2 ! misho 40: // else rewind the file pointer to beginning of the file
1.1 misho 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:
65: echo "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 --
71: array(1) {
72: [0]=>
73: string(39) "This is line of text without csv fields"
74: }
75: int(40)
76: bool(false)
77:
78: -- Testing fgetcsv() with file opened using rb mode --
79: array(1) {
80: [0]=>
81: string(39) "This is line of text without csv fields"
82: }
83: int(40)
84: bool(false)
85:
86: -- Testing fgetcsv() with file opened using rt mode --
87: array(1) {
88: [0]=>
89: string(39) "This is line of text without csv fields"
90: }
91: int(40)
92: bool(false)
93:
94: -- Testing fgetcsv() with file opened using r+ mode --
95: array(1) {
96: [0]=>
97: string(39) "This is line of text without csv fields"
98: }
99: int(40)
100: bool(false)
101:
102: -- Testing fgetcsv() with file opened using r+b mode --
103: array(1) {
104: [0]=>
105: string(39) "This is line of text without csv fields"
106: }
107: int(40)
108: bool(false)
109:
110: -- Testing fgetcsv() with file opened using r+t mode --
111: array(1) {
112: [0]=>
113: string(39) "This is line of text without csv fields"
114: }
115: int(40)
116: bool(false)
117:
118: -- Testing fgetcsv() with file opened using a+ mode --
119: array(1) {
120: [0]=>
121: string(39) "This is line of text without csv fields"
122: }
123: int(40)
124: bool(false)
125:
126: -- Testing fgetcsv() with file opened using a+b mode --
127: array(1) {
128: [0]=>
129: string(39) "This is line of text without csv fields"
130: }
131: int(40)
132: bool(false)
133:
134: -- Testing fgetcsv() with file opened using a+t mode --
135: array(1) {
136: [0]=>
137: string(39) "This is line of text without csv fields"
138: }
139: int(40)
140: bool(false)
141:
142: -- Testing fgetcsv() with file opened using w+ mode --
143: array(1) {
144: [0]=>
145: string(39) "This is line of text without csv fields"
146: }
147: int(40)
148: bool(false)
149:
150: -- Testing fgetcsv() with file opened using w+b mode --
151: array(1) {
152: [0]=>
153: string(39) "This is line of text without csv fields"
154: }
155: int(40)
156: bool(false)
157:
158: -- Testing fgetcsv() with file opened using w+t mode --
159: array(1) {
160: [0]=>
161: string(39) "This is line of text without csv fields"
162: }
163: int(40)
164: bool(false)
165:
166: -- Testing fgetcsv() with file opened using x+ mode --
167: array(1) {
168: [0]=>
169: string(39) "This is line of text without csv fields"
170: }
171: int(40)
172: bool(false)
173:
174: -- Testing fgetcsv() with file opened using x+b mode --
175: array(1) {
176: [0]=>
177: string(39) "This is line of text without csv fields"
178: }
179: int(40)
180: bool(false)
181:
182: -- Testing fgetcsv() with file opened using x+t mode --
183: array(1) {
184: [0]=>
185: string(39) "This is line of text without csv fields"
186: }
187: int(40)
188: bool(false)
189: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>