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