1--TEST--
2Test fgetss() function : usage variations - read  modes, file pointer at EOF
3--SKIPIF--
4<?php
5if(substr(PHP_OS, 0, 3) == "WIN")
6  die("skip not for Windows");
7?>
8--FILE--
9<?php
10/*
11 Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] );
12 Description: Gets line from file pointer and strip HTML tags
13*/
14
15// include the common file related test functions
16include ("file.inc");
17
18echo "*** Testing fgetss() : usage variations  ***\n";
19
20/* string with html and php tags */
21$string_with_tags = <<<EOT
22<test>Testing fgetss() functions</test>
23<?php echo "this string is within php tag"; ?> {;}<{> this
24is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
25<html> html </html> <?php echo "php"; ?>
26this line is without any html and php tags
27this is a line with more than eighty character,want to check line splitting correctly after 80 characters
28this is the text containing \r character
29this text contains some html tags <body> body </body> <br> br </br>
30this is the line with \n character.
31EOT;
32
33$filename = dirname(__FILE__)."/fgetss_variation4.tmp";
34
35/* try reading the file opened in different modes of reading */
36$file_modes = array("r","rb", "rt","r+", "r+b", "r+t");
37
38for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
39  echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
40
41  /* create an empty file and write the strings with tags */
42  create_file ($filename); //create an empty file
43  file_put_contents($filename, $string_with_tags);
44  $file_handle = fopen($filename, $file_modes[$mode_counter]);
45  if(!$file_handle) {
46    echo "Error: failed to open file $filename!\n";
47    exit();
48  }
49
50  // rewind the file pointer to beginning of the file
51  var_dump( filesize($filename) );
52  var_dump( rewind($file_handle) );
53  var_dump( ftell($file_handle) );
54  var_dump( feof($file_handle) );
55
56  echo "-- Reading when file pointer points to EOF --\n";
57  var_dump( fseek($file_handle,0,SEEK_END) ); // now file pointer at end
58  var_dump( ftell($file_handle) ); //ensure file pointer at end
59  var_dump( fgetss($file_handle) ); // try to read
60  var_dump( ftell($file_handle) ); // find out file position
61  var_dump( feof($file_handle) );  // ensure that file pointer is at eof
62
63  // now file is at the end try reading with length and allowable tags,expecting false
64  var_dump( fgetss($file_handle, 80, "<test>, <html>, <?>") );
65  var_dump( ftell($file_handle) );  // find out file position
66  var_dump( feof($file_handle) );   // ensure that file pointer is at eof
67
68  // close the file
69  fclose($file_handle);
70  // delete the file
71  delete_file($filename);
72} // end of for - mode_counter
73
74echo "Done\n";
75?>
76--EXPECTF--
77*** Testing fgetss() : usage variations  ***
78
79-- Testing fgetss() with file opened using r mode --
80int(486)
81bool(true)
82int(0)
83bool(false)
84-- Reading when file pointer points to EOF --
85int(0)
86int(486)
87bool(false)
88int(486)
89bool(true)
90bool(false)
91int(486)
92bool(true)
93
94-- Testing fgetss() with file opened using rb mode --
95int(486)
96bool(true)
97int(0)
98bool(false)
99-- Reading when file pointer points to EOF --
100int(0)
101int(486)
102bool(false)
103int(486)
104bool(true)
105bool(false)
106int(486)
107bool(true)
108
109-- Testing fgetss() with file opened using rt mode --
110int(486)
111bool(true)
112int(0)
113bool(false)
114-- Reading when file pointer points to EOF --
115int(0)
116int(486)
117bool(false)
118int(486)
119bool(true)
120bool(false)
121int(486)
122bool(true)
123
124-- Testing fgetss() with file opened using r+ mode --
125int(486)
126bool(true)
127int(0)
128bool(false)
129-- Reading when file pointer points to EOF --
130int(0)
131int(486)
132bool(false)
133int(486)
134bool(true)
135bool(false)
136int(486)
137bool(true)
138
139-- Testing fgetss() with file opened using r+b mode --
140int(486)
141bool(true)
142int(0)
143bool(false)
144-- Reading when file pointer points to EOF --
145int(0)
146int(486)
147bool(false)
148int(486)
149bool(true)
150bool(false)
151int(486)
152bool(true)
153
154-- Testing fgetss() with file opened using r+t mode --
155int(486)
156bool(true)
157int(0)
158bool(false)
159-- Reading when file pointer points to EOF --
160int(0)
161int(486)
162bool(false)
163int(486)
164bool(true)
165bool(false)
166int(486)
167bool(true)
168Done
169