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