1--TEST--
2Test fgetss() function : Basic functionality - read/write modes
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6    die('skip.. only on Windows');
7}
8?>
9--FILE--
10<?php
11error_reporting(E_ALL & ~E_DEPRECATED);
12
13/*
14 Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] );
15 Description: Gets line from file pointer and strip HTML tags
16*/
17
18/* try fgetss on files which are opened in read/write modes
19    w+, w+b, w+t,
20    a+, a+b, a+t,
21    x+, x+b, x+t
22*/
23
24
25echo "*** Testing fgetss() : basic operations ***\n";
26
27/* string with html and php tags */
28$string_with_tags = <<<EOT
29<test>Testing fgetss() functions</test>
30<?php echo "this string is within php tag"; ?> {;}<{> this
31is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
32<html> html </html> <?php echo "php"; ?>
33EOT;
34if(substr(PHP_OS, 0, 3) == "WIN")  {
35	$string_with_tags = str_replace("\r",'', $string_with_tags);
36}
37$filename = dirname(__FILE__)."/fgetss_basic2私はガラスを食べられます.tmp";
38
39/* try reading the file opened in different modes of reading */
40$file_modes = array("w+","w+b", "w+t","a+", "a+b", "a+t","x+","x+b","x+t");
41
42for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
43  echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
44
45  /* create an empty file and write the strings with tags */
46  $file_handle = fopen($filename, $file_modes[$mode_counter]);
47  fwrite($file_handle,$string_with_tags); //writing data to the file
48  if(!$file_handle) {
49    echo "Error: failed to open file $filename!\n";
50    exit();
51  }
52
53  // rewind the file pointer to beginning of the file
54  var_dump( filesize($filename) );
55  var_dump( rewind($file_handle) );
56  var_dump( ftell($file_handle) );
57  var_dump( feof($file_handle) );
58
59  /* read entire file and strip tags */
60  echo "-- fgetss() with default length, file pointer at 0 --\n";
61  var_dump( fgetss($file_handle) ); // no length and allowable tags provided, reads entire file
62  var_dump( ftell($file_handle) );
63  var_dump( feof($file_handle) );
64
65  rewind($file_handle);
66  /* read entire file and strip tags tags */
67  echo "-- fgets() with length = 30, file pointer at 0 --\n";
68  var_dump( fgetss($file_handle ,30) ); // length parameter given,not reading entire file
69  var_dump( ftell($file_handle) ); // checking file pointer position initially
70  var_dump( feof($file_handle) ); // confirm file pointer is not at eof
71
72  // close the file
73  fclose($file_handle);
74
75  // delete the file
76  unlink($filename);
77} // end of for - mode_counter
78
79echo "Done\n";
80?>
81--EXPECT--
82*** Testing fgetss() : basic operations ***
83
84-- Testing fgetss() with file opened using w+ mode --
85int(192)
86bool(true)
87int(0)
88bool(false)
89-- fgetss() with default length, file pointer at 0 --
90string(27) "Testing fgetss() functions
91"
92int(40)
93bool(false)
94-- fgets() with length = 30, file pointer at 0 --
95string(23) "Testing fgetss() functi"
96int(29)
97bool(false)
98
99-- Testing fgetss() with file opened using w+b mode --
100int(192)
101bool(true)
102int(0)
103bool(false)
104-- fgetss() with default length, file pointer at 0 --
105string(27) "Testing fgetss() functions
106"
107int(40)
108bool(false)
109-- fgets() with length = 30, file pointer at 0 --
110string(23) "Testing fgetss() functi"
111int(29)
112bool(false)
113
114-- Testing fgetss() with file opened using w+t mode --
115int(195)
116bool(true)
117int(0)
118bool(false)
119-- fgetss() with default length, file pointer at 0 --
120string(27) "Testing fgetss() functions
121"
122int(40)
123bool(false)
124-- fgets() with length = 30, file pointer at 0 --
125string(23) "Testing fgetss() functi"
126int(29)
127bool(false)
128
129-- Testing fgetss() with file opened using a+ mode --
130int(192)
131bool(true)
132int(0)
133bool(false)
134-- fgetss() with default length, file pointer at 0 --
135string(27) "Testing fgetss() functions
136"
137int(40)
138bool(false)
139-- fgets() with length = 30, file pointer at 0 --
140string(23) "Testing fgetss() functi"
141int(29)
142bool(false)
143
144-- Testing fgetss() with file opened using a+b mode --
145int(192)
146bool(true)
147int(0)
148bool(false)
149-- fgetss() with default length, file pointer at 0 --
150string(27) "Testing fgetss() functions
151"
152int(40)
153bool(false)
154-- fgets() with length = 30, file pointer at 0 --
155string(23) "Testing fgetss() functi"
156int(29)
157bool(false)
158
159-- Testing fgetss() with file opened using a+t mode --
160int(195)
161bool(true)
162int(0)
163bool(false)
164-- fgetss() with default length, file pointer at 0 --
165string(27) "Testing fgetss() functions
166"
167int(40)
168bool(false)
169-- fgets() with length = 30, file pointer at 0 --
170string(23) "Testing fgetss() functi"
171int(29)
172bool(false)
173
174-- Testing fgetss() with file opened using x+ mode --
175int(192)
176bool(true)
177int(0)
178bool(false)
179-- fgetss() with default length, file pointer at 0 --
180string(27) "Testing fgetss() functions
181"
182int(40)
183bool(false)
184-- fgets() with length = 30, file pointer at 0 --
185string(23) "Testing fgetss() functi"
186int(29)
187bool(false)
188
189-- Testing fgetss() with file opened using x+b mode --
190int(192)
191bool(true)
192int(0)
193bool(false)
194-- fgetss() with default length, file pointer at 0 --
195string(27) "Testing fgetss() functions
196"
197int(40)
198bool(false)
199-- fgets() with length = 30, file pointer at 0 --
200string(23) "Testing fgetss() functi"
201int(29)
202bool(false)
203
204-- Testing fgetss() with file opened using x+t mode --
205int(195)
206bool(true)
207int(0)
208bool(false)
209-- fgetss() with default length, file pointer at 0 --
210string(27) "Testing fgetss() functions
211"
212int(40)
213bool(false)
214-- fgets() with length = 30, file pointer at 0 --
215string(23) "Testing fgetss() functi"
216int(29)
217bool(false)
218Done
219