![]() ![]() | ![]() |
1.1 misho 1: --TEST--
2: Test fgetc() function : usage variations - different read modes
3: --FILE--
4: <?php
5: /*
6: Prototype: string fgetc ( resource $handle );
7: Description: Gets character from file pointer
8: */
9:
10: /* read from fie using fgetc, file opened using different
11: read read modes */
12:
13: echo "*** Testing fgetc() : usage variations ***\n";
14: echo "-- Testing fgetc() with files opened with different read modes --\n";
15:
16: $file_modes = array( "a+", "a+b", "a+t",
17: "x+", "x+b", "x+t",
18: "w+", "w+b", "w+t" );
19:
20: $filename = dirname(__FILE__)."/fgetc_variation4.tmp";
21: foreach ($file_modes as $file_mode ) {
22: echo "-- File opened in mode : $file_mode --\n";
23:
24: $file_handle = fopen($filename, $file_mode);
25: if(!$file_handle) {
26: echo "Error: failed to open file $filename!\n";
27: exit();
28: }
29: $data = "fgetc\n test";
30: fwrite($file_handle, $data);
31:
1.1.1.2 ! misho 32: // rewind the file pointer to beginning of the file
1.1 misho 33: var_dump( rewind($file_handle) );
34: var_dump( ftell($file_handle) );
35: var_dump( feof($file_handle) );
36:
37: // read from file, at least 7 chars
38: for($counter =0; $counter < 7; $counter ++) {
39: var_dump( fgetc($file_handle) ); // expected : 1 char
40: var_dump( ftell($file_handle) );
41: var_dump( feof($file_handle) ); // check if end of file pointer is set
42: }
43:
44: // close the file
45: fclose($file_handle);
46:
47: // delete the file
48: unlink($filename);
49: }
50:
51: echo "Done\n";
52: ?>
53: --EXPECTF--
54: *** Testing fgetc() : usage variations ***
55: -- Testing fgetc() with files opened with different read modes --
56: -- File opened in mode : a+ --
57: bool(true)
58: int(0)
59: bool(false)
60: string(1) "f"
61: int(1)
62: bool(false)
63: string(1) "g"
64: int(2)
65: bool(false)
66: string(1) "e"
67: int(3)
68: bool(false)
69: string(1) "t"
70: int(4)
71: bool(false)
72: string(1) "c"
73: int(5)
74: bool(false)
75: string(1) "
76: "
77: int(6)
78: bool(false)
79: string(1) " "
80: int(7)
81: bool(false)
82: -- File opened in mode : a+b --
83: bool(true)
84: int(0)
85: bool(false)
86: string(1) "f"
87: int(1)
88: bool(false)
89: string(1) "g"
90: int(2)
91: bool(false)
92: string(1) "e"
93: int(3)
94: bool(false)
95: string(1) "t"
96: int(4)
97: bool(false)
98: string(1) "c"
99: int(5)
100: bool(false)
101: string(1) "
102: "
103: int(6)
104: bool(false)
105: string(1) " "
106: int(7)
107: bool(false)
108: -- File opened in mode : a+t --
109: bool(true)
110: int(0)
111: bool(false)
112: string(1) "f"
113: int(1)
114: bool(false)
115: string(1) "g"
116: int(2)
117: bool(false)
118: string(1) "e"
119: int(3)
120: bool(false)
121: string(1) "t"
122: int(4)
123: bool(false)
124: string(1) "c"
125: int(5)
126: bool(false)
127: string(1) "
128: "
129: int(6)
130: bool(false)
131: string(1) " "
132: int(7)
133: bool(false)
134: -- File opened in mode : x+ --
135: bool(true)
136: int(0)
137: bool(false)
138: string(1) "f"
139: int(1)
140: bool(false)
141: string(1) "g"
142: int(2)
143: bool(false)
144: string(1) "e"
145: int(3)
146: bool(false)
147: string(1) "t"
148: int(4)
149: bool(false)
150: string(1) "c"
151: int(5)
152: bool(false)
153: string(1) "
154: "
155: int(6)
156: bool(false)
157: string(1) " "
158: int(7)
159: bool(false)
160: -- File opened in mode : x+b --
161: bool(true)
162: int(0)
163: bool(false)
164: string(1) "f"
165: int(1)
166: bool(false)
167: string(1) "g"
168: int(2)
169: bool(false)
170: string(1) "e"
171: int(3)
172: bool(false)
173: string(1) "t"
174: int(4)
175: bool(false)
176: string(1) "c"
177: int(5)
178: bool(false)
179: string(1) "
180: "
181: int(6)
182: bool(false)
183: string(1) " "
184: int(7)
185: bool(false)
186: -- File opened in mode : x+t --
187: bool(true)
188: int(0)
189: bool(false)
190: string(1) "f"
191: int(1)
192: bool(false)
193: string(1) "g"
194: int(2)
195: bool(false)
196: string(1) "e"
197: int(3)
198: bool(false)
199: string(1) "t"
200: int(4)
201: bool(false)
202: string(1) "c"
203: int(5)
204: bool(false)
205: string(1) "
206: "
207: int(6)
208: bool(false)
209: string(1) " "
210: int(7)
211: bool(false)
212: -- File opened in mode : w+ --
213: bool(true)
214: int(0)
215: bool(false)
216: string(1) "f"
217: int(1)
218: bool(false)
219: string(1) "g"
220: int(2)
221: bool(false)
222: string(1) "e"
223: int(3)
224: bool(false)
225: string(1) "t"
226: int(4)
227: bool(false)
228: string(1) "c"
229: int(5)
230: bool(false)
231: string(1) "
232: "
233: int(6)
234: bool(false)
235: string(1) " "
236: int(7)
237: bool(false)
238: -- File opened in mode : w+b --
239: bool(true)
240: int(0)
241: bool(false)
242: string(1) "f"
243: int(1)
244: bool(false)
245: string(1) "g"
246: int(2)
247: bool(false)
248: string(1) "e"
249: int(3)
250: bool(false)
251: string(1) "t"
252: int(4)
253: bool(false)
254: string(1) "c"
255: int(5)
256: bool(false)
257: string(1) "
258: "
259: int(6)
260: bool(false)
261: string(1) " "
262: int(7)
263: bool(false)
264: -- File opened in mode : w+t --
265: bool(true)
266: int(0)
267: bool(false)
268: string(1) "f"
269: int(1)
270: bool(false)
271: string(1) "g"
272: int(2)
273: bool(false)
274: string(1) "e"
275: int(3)
276: bool(false)
277: string(1) "t"
278: int(4)
279: bool(false)
280: string(1) "c"
281: int(5)
282: bool(false)
283: string(1) "
284: "
285: int(6)
286: bool(false)
287: string(1) " "
288: int(7)
289: bool(false)
290: Done