1--TEST--
2Test fgetss() function : Basic functionality - read/write modes
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip.. Not 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*/
21
22
23echo "*** Testing fgetss() : basic operations ***\n";
24
25/* string with html and php tags */
26$string_with_tags = <<<EOT
27<test>Testing fgetss() functions</test>
28<?php echo "this string is within php tag"; ?> {;}<{> this
29is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
30<html> html </html> <?php echo "php"; ?>
31EOT;
32
33$filename = dirname(__FILE__)."/fgetss_basic2.tmp";
34
35/* try reading the file opened in different modes of reading */
36$file_modes = array("w+","w+b", "w+t","a+", "a+b", "a+t","x+","x+b","x+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  $file_handle = fopen($filename, $file_modes[$mode_counter]);
43  fwrite($file_handle,$string_with_tags); //writing data to the file
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  /* read entire file and strip tags */
56  echo "-- fgetss() with default length, file pointer at 0 --\n";
57  var_dump( fgetss($file_handle) ); // no length and allowable tags provided, reads entire file
58  var_dump( ftell($file_handle) );
59  var_dump( feof($file_handle) );
60
61  rewind($file_handle);
62  /* read entire file and strip tags tags */
63  echo "-- fgets() with length = 30, file pointer at 0 --\n";
64  var_dump( fgetss($file_handle ,30) ); // length parameter given,not reading entire file
65  var_dump( ftell($file_handle) ); // checking file pointer position initially
66  var_dump( feof($file_handle) ); // confirm file pointer is not at eof
67
68  // close the file
69  fclose($file_handle);
70
71  // delete the file
72  unlink($filename);
73} // end of for - mode_counter
74
75echo "Done\n";
76?>
77--EXPECTF--
78*** Testing fgetss() : basic operations ***
79
80-- Testing fgetss() with file opened using w+ mode --
81int(192)
82bool(true)
83int(0)
84bool(false)
85-- fgetss() with default length, file pointer at 0 --
86string(27) "Testing fgetss() functions
87"
88int(40)
89bool(false)
90-- fgets() with length = 30, file pointer at 0 --
91string(23) "Testing fgetss() functi"
92int(29)
93bool(false)
94
95-- Testing fgetss() with file opened using w+b mode --
96int(192)
97bool(true)
98int(0)
99bool(false)
100-- fgetss() with default length, file pointer at 0 --
101string(27) "Testing fgetss() functions
102"
103int(40)
104bool(false)
105-- fgets() with length = 30, file pointer at 0 --
106string(23) "Testing fgetss() functi"
107int(29)
108bool(false)
109
110-- Testing fgetss() with file opened using w+t mode --
111int(192)
112bool(true)
113int(0)
114bool(false)
115-- fgetss() with default length, file pointer at 0 --
116string(27) "Testing fgetss() functions
117"
118int(40)
119bool(false)
120-- fgets() with length = 30, file pointer at 0 --
121string(23) "Testing fgetss() functi"
122int(29)
123bool(false)
124
125-- Testing fgetss() with file opened using a+ mode --
126int(192)
127bool(true)
128int(0)
129bool(false)
130-- fgetss() with default length, file pointer at 0 --
131string(27) "Testing fgetss() functions
132"
133int(40)
134bool(false)
135-- fgets() with length = 30, file pointer at 0 --
136string(23) "Testing fgetss() functi"
137int(29)
138bool(false)
139
140-- Testing fgetss() with file opened using a+b mode --
141int(192)
142bool(true)
143int(0)
144bool(false)
145-- fgetss() with default length, file pointer at 0 --
146string(27) "Testing fgetss() functions
147"
148int(40)
149bool(false)
150-- fgets() with length = 30, file pointer at 0 --
151string(23) "Testing fgetss() functi"
152int(29)
153bool(false)
154
155-- Testing fgetss() with file opened using a+t mode --
156int(192)
157bool(true)
158int(0)
159bool(false)
160-- fgetss() with default length, file pointer at 0 --
161string(27) "Testing fgetss() functions
162"
163int(40)
164bool(false)
165-- fgets() with length = 30, file pointer at 0 --
166string(23) "Testing fgetss() functi"
167int(29)
168bool(false)
169
170-- Testing fgetss() with file opened using x+ mode --
171int(192)
172bool(true)
173int(0)
174bool(false)
175-- fgetss() with default length, file pointer at 0 --
176string(27) "Testing fgetss() functions
177"
178int(40)
179bool(false)
180-- fgets() with length = 30, file pointer at 0 --
181string(23) "Testing fgetss() functi"
182int(29)
183bool(false)
184
185-- Testing fgetss() with file opened using x+b mode --
186int(192)
187bool(true)
188int(0)
189bool(false)
190-- fgetss() with default length, file pointer at 0 --
191string(27) "Testing fgetss() functions
192"
193int(40)
194bool(false)
195-- fgets() with length = 30, file pointer at 0 --
196string(23) "Testing fgetss() functi"
197int(29)
198bool(false)
199
200-- Testing fgetss() with file opened using x+t mode --
201int(192)
202bool(true)
203int(0)
204bool(false)
205-- fgetss() with default length, file pointer at 0 --
206string(27) "Testing fgetss() functions
207"
208int(40)
209bool(false)
210-- fgets() with length = 30, file pointer at 0 --
211string(23) "Testing fgetss() functi"
212int(29)
213bool(false)
214Done
215