1--TEST--
2Test fgetss() function : usage variations - read modes
3--FILE--
4<?php
5/*
6 Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] );
7 Description: Gets line from file pointer and strip HTML tags
8*/
9
10// include the common file related test functions
11include ("file.inc");
12
13/*Test fgetss() with all read modes , reading line by line with allowable tags: <test>, <html>, <?> */
14
15echo "*** Testing fgetss() : usage variations  ***\n";
16
17/* string with html and php tags */
18$string_with_tags = <<<EOT
19<test>Testing fgetss() functions</test>
20<?php echo "this string is within php tag"; ?> {;}<{> this
21is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
22<html> html </html> <?php echo "php"; ?>
23this line is without any html and php tags
24this is a line with more than eighty character,want to check line splitting correctly after 80 characters
25this is the text containing \r character
26this text contains some html tags <body> body </body> <br> br </br>
27this is the line with \n character.
28EOT;
29
30$filename = dirname(__FILE__)."/fgetss_variation2.tmp";
31
32/* try reading the file opened in different modes of reading */
33$file_modes = array("r","rb", "rt","r+", "r+b", "r+t");
34
35for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
36  echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
37
38  /* create an empty file and write the strings with tags */
39  create_file ($filename); //create an empty file
40  file_put_contents($filename, $string_with_tags);
41  $file_handle = fopen($filename, $file_modes[$mode_counter]);
42  if(!$file_handle) {
43    echo "Error: failed to open file $filename!\n";
44    exit();
45  }
46
47  // rewind the file pointer to begining of the file
48  var_dump( filesize($filename) );
49  var_dump( rewind($file_handle) );
50  var_dump( ftell($file_handle) );
51  var_dump( feof($file_handle) );
52
53  /* rewind the file and read the file  line by line with allowable tags */
54  echo "-- Reading line by line with allowable tags: <test>, <html>, <?> --\n";
55  rewind($file_handle);
56  $line = 1;
57  while( !feof($file_handle) ) {
58     echo "-- Line $line --\n"; $line++;
59     var_dump( fgetss($file_handle, 80, "<test>, <html>, <?>") );
60     var_dump( ftell($file_handle) );  // check the file pointer position
61     var_dump( feof($file_handle) );  // check if eof reached
62  }
63
64  // close the file
65  fclose($file_handle);
66  // delete the file
67  delete_file($filename);
68} // end of for - mode_counter
69
70echo "Done\n";
71?>
72--EXPECTF--
73*** Testing fgetss() : usage variations  ***
74
75-- Testing fgetss() with file opened using r mode --
76int(486)
77bool(true)
78int(0)
79bool(false)
80-- Reading line by line with allowable tags: <test>, <html>, <?> --
81-- Line 1 --
82string(40) "<test>Testing fgetss() functions</test>
83"
84int(40)
85bool(false)
86-- Line 2 --
87string(10) " {;} this
88"
89int(99)
90bool(false)
91-- Line 3 --
92string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
93"
94int(152)
95bool(false)
96-- Line 4 --
97string(21) "<html> html </html>
98"
99int(193)
100bool(false)
101-- Line 5 --
102string(43) "this line is without any html and php tags
103"
104int(236)
105bool(false)
106-- Line 6 --
107string(79) "this is a line with more than eighty character,want to check line splitting cor"
108int(315)
109bool(false)
110-- Line 7 --
111string(27) "rectly after 80 characters
112"
113int(342)
114bool(false)
115-- Line 8 --
116string(41) "this is the text containing
116 character
117"
118int(383)
119bool(false)
120-- Line 9 --
121string(46) "this text contains some html tags  body   br
122"
123int(451)
124bool(false)
125-- Line 10 --
126string(23) "this is the line with
127"
128int(474)
129bool(false)
130-- Line 11 --
131string(12) " character. "
132int(486)
133bool(true)
134
135-- Testing fgetss() with file opened using rb mode --
136int(486)
137bool(true)
138int(0)
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(41) "this is the text containing
176 character
177"
178int(383)
179bool(false)
180-- Line 9 --
181string(46) "this text contains some html tags  body   br
182"
183int(451)
184bool(false)
185-- Line 10 --
186string(23) "this is the line with
187"
188int(474)
189bool(false)
190-- Line 11 --
191string(12) " character. "
192int(486)
193bool(true)
194
195-- Testing fgetss() with file opened using rt mode --
196int(486)
197bool(true)
198int(0)
199bool(false)
200-- Reading line by line with allowable tags: <test>, <html>, <?> --
201-- Line 1 --
202string(40) "<test>Testing fgetss() functions</test>
203"
204int(40)
205bool(false)
206-- Line 2 --
207string(10) " {;} this
208"
209int(99)
210bool(false)
211-- Line 3 --
212string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
213"
214int(152)
215bool(false)
216-- Line 4 --
217string(21) "<html> html </html>
218"
219int(193)
220bool(false)
221-- Line 5 --
222string(43) "this line is without any html and php tags
223"
224int(236)
225bool(false)
226-- Line 6 --
227string(79) "this is a line with more than eighty character,want to check line splitting cor"
228int(315)
229bool(false)
230-- Line 7 --
231string(27) "rectly after 80 characters
232"
233int(342)
234bool(false)
235-- Line 8 --
236string(41) "this is the text containing
236 character
237"
238int(383)
239bool(false)
240-- Line 9 --
241string(46) "this text contains some html tags  body   br
242"
243int(451)
244bool(false)
245-- Line 10 --
246string(23) "this is the line with
247"
248int(474)
249bool(false)
250-- Line 11 --
251string(12) " character. "
252int(486)
253bool(true)
254
255-- Testing fgetss() with file opened using r+ mode --
256int(486)
257bool(true)
258int(0)
259bool(false)
260-- Reading line by line with allowable tags: <test>, <html>, <?> --
261-- Line 1 --
262string(40) "<test>Testing fgetss() functions</test>
263"
264int(40)
265bool(false)
266-- Line 2 --
267string(10) " {;} this
268"
269int(99)
270bool(false)
271-- Line 3 --
272string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
273"
274int(152)
275bool(false)
276-- Line 4 --
277string(21) "<html> html </html>
278"
279int(193)
280bool(false)
281-- Line 5 --
282string(43) "this line is without any html and php tags
283"
284int(236)
285bool(false)
286-- Line 6 --
287string(79) "this is a line with more than eighty character,want to check line splitting cor"
288int(315)
289bool(false)
290-- Line 7 --
291string(27) "rectly after 80 characters
292"
293int(342)
294bool(false)
295-- Line 8 --
296string(41) "this is the text containing
296 character
297"
298int(383)
299bool(false)
300-- Line 9 --
301string(46) "this text contains some html tags  body   br
302"
303int(451)
304bool(false)
305-- Line 10 --
306string(23) "this is the line with
307"
308int(474)
309bool(false)
310-- Line 11 --
311string(12) " character. "
312int(486)
313bool(true)
314
315-- Testing fgetss() with file opened using r+b mode --
316int(486)
317bool(true)
318int(0)
319bool(false)
320-- Reading line by line with allowable tags: <test>, <html>, <?> --
321-- Line 1 --
322string(40) "<test>Testing fgetss() functions</test>
323"
324int(40)
325bool(false)
326-- Line 2 --
327string(10) " {;} this
328"
329int(99)
330bool(false)
331-- Line 3 --
332string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
333"
334int(152)
335bool(false)
336-- Line 4 --
337string(21) "<html> html </html>
338"
339int(193)
340bool(false)
341-- Line 5 --
342string(43) "this line is without any html and php tags
343"
344int(236)
345bool(false)
346-- Line 6 --
347string(79) "this is a line with more than eighty character,want to check line splitting cor"
348int(315)
349bool(false)
350-- Line 7 --
351string(27) "rectly after 80 characters
352"
353int(342)
354bool(false)
355-- Line 8 --
356string(41) "this is the text containing
356 character
357"
358int(383)
359bool(false)
360-- Line 9 --
361string(46) "this text contains some html tags  body   br
362"
363int(451)
364bool(false)
365-- Line 10 --
366string(23) "this is the line with
367"
368int(474)
369bool(false)
370-- Line 11 --
371string(12) " character. "
372int(486)
373bool(true)
374
375-- Testing fgetss() with file opened using r+t mode --
376int(486)
377bool(true)
378int(0)
379bool(false)
380-- Reading line by line with allowable tags: <test>, <html>, <?> --
381-- Line 1 --
382string(40) "<test>Testing fgetss() functions</test>
383"
384int(40)
385bool(false)
386-- Line 2 --
387string(10) " {;} this
388"
389int(99)
390bool(false)
391-- Line 3 --
392string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
393"
394int(152)
395bool(false)
396-- Line 4 --
397string(21) "<html> html </html>
398"
399int(193)
400bool(false)
401-- Line 5 --
402string(43) "this line is without any html and php tags
403"
404int(236)
405bool(false)
406-- Line 6 --
407string(79) "this is a line with more than eighty character,want to check line splitting cor"
408int(315)
409bool(false)
410-- Line 7 --
411string(27) "rectly after 80 characters
412"
413int(342)
414bool(false)
415-- Line 8 --
416string(41) "this is the text containing
416 character
417"
418int(383)
419bool(false)
420-- Line 9 --
421string(46) "this text contains some html tags  body   br
422"
423int(451)
424bool(false)
425-- Line 10 --
426string(23) "this is the line with
427"
428int(474)
429bool(false)
430-- Line 11 --
431string(12) " character. "
432int(486)
433bool(true)
434Done
435