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