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