1--TEST--
2Test fgets() function : usage variations - seek n read
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6    die('skip only valid for Windows');
7}
8?>
9--FILE--
10<?php
11// include the file.inc for common test functions
12include ("file.inc");
13
14$file_modes = array("w+", "w+b", "w+t",
15                    "a+", "a+b", "a+t",
16                    "x+", "x+b", "x+t");
17
18$file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
19
20echo "*** Testing fgets() : usage variations ***\n";
21
22$filename = __DIR__."/fgets_variation4私はガラスを食べられます.tmp";
23
24foreach($file_modes as $file_mode) {
25  echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";
26
27  foreach($file_content_types as $file_content_type) {
28    echo "-- File content type : $file_content_type --\n";
29
30    /* create files with $file_content_type */
31    $file_handle = fopen($filename, $file_mode);
32    $data = fill_file($file_handle, $file_content_type, 50);
33
34    if ( !$file_handle ) {
35      echo "Error: failed to open file $filename!";
36      exit();
37    }
38
39    echo "-- fgets() with location set by fseek() with default length --\n";
40    var_dump( fseek($file_handle, 5, SEEK_SET) );
41    var_dump( ftell($file_handle) );
42    var_dump( fgets($file_handle ) );
43    var_dump( ftell($file_handle) ); // ensure the file pointer position
44    var_dump( feof($file_handle) );  // ensure if eof set
45
46    echo "-- fgets() with location set by fseek() with length = 20 --\n";
47    var_dump( fseek($file_handle, 25, SEEK_SET) );
48    var_dump( ftell($file_handle) );
49    var_dump( fgets($file_handle, 20 ) ); // expected 19 chars
50    var_dump( ftell($file_handle) ); // ensure the file pointer position
51    var_dump( feof($file_handle) );  // ensure if eof set
52
53    //close file
54    fclose($file_handle);
55
56    // delete file
57    delete_file($filename);
58  } // file_content_type loop
59} // file_mode loop
60
61echo "Done\n";
62?>
63--EXPECT--
64*** Testing fgets() : usage variations ***
65
66-- Testing fgets() with file opened using mode w+ --
67-- File content type : numeric --
68-- fgets() with location set by fseek() with default length --
69int(0)
70int(5)
71string(45) "222222222222222222222222222222222222222222222"
72int(50)
73bool(true)
74-- fgets() with location set by fseek() with length = 20 --
75int(0)
76int(25)
77string(19) "2222222222222222222"
78int(44)
79bool(false)
80-- File content type : text --
81-- fgets() with location set by fseek() with default length --
82int(0)
83int(5)
84string(45) "text text text text text text text text text "
85int(50)
86bool(true)
87-- fgets() with location set by fseek() with length = 20 --
88int(0)
89int(25)
90string(19) "text text text text"
91int(44)
92bool(false)
93-- File content type : text_with_new_line --
94-- fgets() with location set by fseek() with default length --
95int(0)
96int(5)
97string(13) "line of text
98"
99int(18)
100bool(false)
101-- fgets() with location set by fseek() with length = 20 --
102int(0)
103int(25)
104string(11) "ne of text
105"
106int(36)
107bool(false)
108-- File content type : alphanumeric --
109-- fgets() with location set by fseek() with default length --
110int(0)
111int(5)
112string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
113int(50)
114bool(true)
115-- fgets() with location set by fseek() with length = 20 --
116int(0)
117int(25)
118string(19) "ab12 ab12 ab12 ab12"
119int(44)
120bool(false)
121
122-- Testing fgets() with file opened using mode w+b --
123-- File content type : numeric --
124-- fgets() with location set by fseek() with default length --
125int(0)
126int(5)
127string(45) "222222222222222222222222222222222222222222222"
128int(50)
129bool(true)
130-- fgets() with location set by fseek() with length = 20 --
131int(0)
132int(25)
133string(19) "2222222222222222222"
134int(44)
135bool(false)
136-- File content type : text --
137-- fgets() with location set by fseek() with default length --
138int(0)
139int(5)
140string(45) "text text text text text text text text text "
141int(50)
142bool(true)
143-- fgets() with location set by fseek() with length = 20 --
144int(0)
145int(25)
146string(19) "text text text text"
147int(44)
148bool(false)
149-- File content type : text_with_new_line --
150-- fgets() with location set by fseek() with default length --
151int(0)
152int(5)
153string(13) "line of text
154"
155int(18)
156bool(false)
157-- fgets() with location set by fseek() with length = 20 --
158int(0)
159int(25)
160string(11) "ne of text
161"
162int(36)
163bool(false)
164-- File content type : alphanumeric --
165-- fgets() with location set by fseek() with default length --
166int(0)
167int(5)
168string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
169int(50)
170bool(true)
171-- fgets() with location set by fseek() with length = 20 --
172int(0)
173int(25)
174string(19) "ab12 ab12 ab12 ab12"
175int(44)
176bool(false)
177
178-- Testing fgets() with file opened using mode w+t --
179-- File content type : numeric --
180-- fgets() with location set by fseek() with default length --
181int(0)
182int(5)
183string(45) "222222222222222222222222222222222222222222222"
184int(50)
185bool(true)
186-- fgets() with location set by fseek() with length = 20 --
187int(0)
188int(25)
189string(19) "2222222222222222222"
190int(44)
191bool(false)
192-- File content type : text --
193-- fgets() with location set by fseek() with default length --
194int(0)
195int(5)
196string(45) "text text text text text text text text text "
197int(50)
198bool(true)
199-- fgets() with location set by fseek() with length = 20 --
200int(0)
201int(25)
202string(19) "text text text text"
203int(44)
204bool(false)
205-- File content type : text_with_new_line --
206-- fgets() with location set by fseek() with default length --
207int(0)
208int(5)
209string(1) "
210"
211int(6)
212bool(false)
213-- fgets() with location set by fseek() with length = 20 --
214int(0)
215int(25)
216string(12) "ine of text
217"
218int(37)
219bool(false)
220-- File content type : alphanumeric --
221-- fgets() with location set by fseek() with default length --
222int(0)
223int(5)
224string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
225int(50)
226bool(true)
227-- fgets() with location set by fseek() with length = 20 --
228int(0)
229int(25)
230string(19) "ab12 ab12 ab12 ab12"
231int(44)
232bool(false)
233
234-- Testing fgets() with file opened using mode a+ --
235-- File content type : numeric --
236-- fgets() with location set by fseek() with default length --
237int(0)
238int(5)
239string(45) "222222222222222222222222222222222222222222222"
240int(50)
241bool(true)
242-- fgets() with location set by fseek() with length = 20 --
243int(0)
244int(25)
245string(19) "2222222222222222222"
246int(44)
247bool(false)
248-- File content type : text --
249-- fgets() with location set by fseek() with default length --
250int(0)
251int(5)
252string(45) "text text text text text text text text text "
253int(50)
254bool(true)
255-- fgets() with location set by fseek() with length = 20 --
256int(0)
257int(25)
258string(19) "text text text text"
259int(44)
260bool(false)
261-- File content type : text_with_new_line --
262-- fgets() with location set by fseek() with default length --
263int(0)
264int(5)
265string(13) "line of text
266"
267int(18)
268bool(false)
269-- fgets() with location set by fseek() with length = 20 --
270int(0)
271int(25)
272string(11) "ne of text
273"
274int(36)
275bool(false)
276-- File content type : alphanumeric --
277-- fgets() with location set by fseek() with default length --
278int(0)
279int(5)
280string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
281int(50)
282bool(true)
283-- fgets() with location set by fseek() with length = 20 --
284int(0)
285int(25)
286string(19) "ab12 ab12 ab12 ab12"
287int(44)
288bool(false)
289
290-- Testing fgets() with file opened using mode a+b --
291-- File content type : numeric --
292-- fgets() with location set by fseek() with default length --
293int(0)
294int(5)
295string(45) "222222222222222222222222222222222222222222222"
296int(50)
297bool(true)
298-- fgets() with location set by fseek() with length = 20 --
299int(0)
300int(25)
301string(19) "2222222222222222222"
302int(44)
303bool(false)
304-- File content type : text --
305-- fgets() with location set by fseek() with default length --
306int(0)
307int(5)
308string(45) "text text text text text text text text text "
309int(50)
310bool(true)
311-- fgets() with location set by fseek() with length = 20 --
312int(0)
313int(25)
314string(19) "text text text text"
315int(44)
316bool(false)
317-- File content type : text_with_new_line --
318-- fgets() with location set by fseek() with default length --
319int(0)
320int(5)
321string(13) "line of text
322"
323int(18)
324bool(false)
325-- fgets() with location set by fseek() with length = 20 --
326int(0)
327int(25)
328string(11) "ne of text
329"
330int(36)
331bool(false)
332-- File content type : alphanumeric --
333-- fgets() with location set by fseek() with default length --
334int(0)
335int(5)
336string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
337int(50)
338bool(true)
339-- fgets() with location set by fseek() with length = 20 --
340int(0)
341int(25)
342string(19) "ab12 ab12 ab12 ab12"
343int(44)
344bool(false)
345
346-- Testing fgets() with file opened using mode a+t --
347-- File content type : numeric --
348-- fgets() with location set by fseek() with default length --
349int(0)
350int(5)
351string(45) "222222222222222222222222222222222222222222222"
352int(50)
353bool(true)
354-- fgets() with location set by fseek() with length = 20 --
355int(0)
356int(25)
357string(19) "2222222222222222222"
358int(44)
359bool(false)
360-- File content type : text --
361-- fgets() with location set by fseek() with default length --
362int(0)
363int(5)
364string(45) "text text text text text text text text text "
365int(50)
366bool(true)
367-- fgets() with location set by fseek() with length = 20 --
368int(0)
369int(25)
370string(19) "text text text text"
371int(44)
372bool(false)
373-- File content type : text_with_new_line --
374-- fgets() with location set by fseek() with default length --
375int(0)
376int(5)
377string(1) "
378"
379int(6)
380bool(false)
381-- fgets() with location set by fseek() with length = 20 --
382int(0)
383int(25)
384string(12) "ine of text
385"
386int(37)
387bool(false)
388-- File content type : alphanumeric --
389-- fgets() with location set by fseek() with default length --
390int(0)
391int(5)
392string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
393int(50)
394bool(true)
395-- fgets() with location set by fseek() with length = 20 --
396int(0)
397int(25)
398string(19) "ab12 ab12 ab12 ab12"
399int(44)
400bool(false)
401
402-- Testing fgets() with file opened using mode x+ --
403-- File content type : numeric --
404-- fgets() with location set by fseek() with default length --
405int(0)
406int(5)
407string(45) "222222222222222222222222222222222222222222222"
408int(50)
409bool(true)
410-- fgets() with location set by fseek() with length = 20 --
411int(0)
412int(25)
413string(19) "2222222222222222222"
414int(44)
415bool(false)
416-- File content type : text --
417-- fgets() with location set by fseek() with default length --
418int(0)
419int(5)
420string(45) "text text text text text text text text text "
421int(50)
422bool(true)
423-- fgets() with location set by fseek() with length = 20 --
424int(0)
425int(25)
426string(19) "text text text text"
427int(44)
428bool(false)
429-- File content type : text_with_new_line --
430-- fgets() with location set by fseek() with default length --
431int(0)
432int(5)
433string(13) "line of text
434"
435int(18)
436bool(false)
437-- fgets() with location set by fseek() with length = 20 --
438int(0)
439int(25)
440string(11) "ne of text
441"
442int(36)
443bool(false)
444-- File content type : alphanumeric --
445-- fgets() with location set by fseek() with default length --
446int(0)
447int(5)
448string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
449int(50)
450bool(true)
451-- fgets() with location set by fseek() with length = 20 --
452int(0)
453int(25)
454string(19) "ab12 ab12 ab12 ab12"
455int(44)
456bool(false)
457
458-- Testing fgets() with file opened using mode x+b --
459-- File content type : numeric --
460-- fgets() with location set by fseek() with default length --
461int(0)
462int(5)
463string(45) "222222222222222222222222222222222222222222222"
464int(50)
465bool(true)
466-- fgets() with location set by fseek() with length = 20 --
467int(0)
468int(25)
469string(19) "2222222222222222222"
470int(44)
471bool(false)
472-- File content type : text --
473-- fgets() with location set by fseek() with default length --
474int(0)
475int(5)
476string(45) "text text text text text text text text text "
477int(50)
478bool(true)
479-- fgets() with location set by fseek() with length = 20 --
480int(0)
481int(25)
482string(19) "text text text text"
483int(44)
484bool(false)
485-- File content type : text_with_new_line --
486-- fgets() with location set by fseek() with default length --
487int(0)
488int(5)
489string(13) "line of text
490"
491int(18)
492bool(false)
493-- fgets() with location set by fseek() with length = 20 --
494int(0)
495int(25)
496string(11) "ne of text
497"
498int(36)
499bool(false)
500-- File content type : alphanumeric --
501-- fgets() with location set by fseek() with default length --
502int(0)
503int(5)
504string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
505int(50)
506bool(true)
507-- fgets() with location set by fseek() with length = 20 --
508int(0)
509int(25)
510string(19) "ab12 ab12 ab12 ab12"
511int(44)
512bool(false)
513
514-- Testing fgets() with file opened using mode x+t --
515-- File content type : numeric --
516-- fgets() with location set by fseek() with default length --
517int(0)
518int(5)
519string(45) "222222222222222222222222222222222222222222222"
520int(50)
521bool(true)
522-- fgets() with location set by fseek() with length = 20 --
523int(0)
524int(25)
525string(19) "2222222222222222222"
526int(44)
527bool(false)
528-- File content type : text --
529-- fgets() with location set by fseek() with default length --
530int(0)
531int(5)
532string(45) "text text text text text text text text text "
533int(50)
534bool(true)
535-- fgets() with location set by fseek() with length = 20 --
536int(0)
537int(25)
538string(19) "text text text text"
539int(44)
540bool(false)
541-- File content type : text_with_new_line --
542-- fgets() with location set by fseek() with default length --
543int(0)
544int(5)
545string(1) "
546"
547int(6)
548bool(false)
549-- fgets() with location set by fseek() with length = 20 --
550int(0)
551int(25)
552string(12) "ine of text
553"
554int(37)
555bool(false)
556-- File content type : alphanumeric --
557-- fgets() with location set by fseek() with default length --
558int(0)
559int(5)
560string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
561int(50)
562bool(true)
563-- fgets() with location set by fseek() with length = 20 --
564int(0)
565int(25)
566string(19) "ab12 ab12 ab12 ab12"
567int(44)
568bool(false)
569Done
570