1--TEST--
2Test fgetss() function : Basic functionality - read modes only
3--FILE--
4<?php
5/*
6 Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] );
7 Description: Gets line from file pointer and strip HTML tags
8*/
9
10/* test fgetss with all read modes */
11
12// include the common file related test functions
13include ("file.inc");
14
15echo "*** Testing fgetss() : Basic operations ***\n";
16
17/* string with html and php tags */
18$string_with_tags = <<<EOT
19<test>Testing fgetss() functions</test>
20<?php echo "this string is within php tag"; ?> {;}<{> this
21is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
22<html> html </html> <?php echo "php"; ?>
23EOT;
24
25if(substr(PHP_OS, 0, 3) == "WIN")  {
26	$string_with_tags = str_replace("\r",'', $string_with_tags);
27}
28/* try reading the file opened in different modes of reading */
29$file_modes = array("r","rb", "rt","r+", "r+b", "r+t");
30
31for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
32  echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
33
34  /* create an empty file and write the strings with tags */
35  $filename = dirname(__FILE__)."/fgetss_basic1.tmp";
36  create_file ($filename); //create an empty file
37  file_put_contents($filename, $string_with_tags);
38  $file_handle = fopen($filename, $file_modes[$mode_counter]);
39  if(!$file_handle) {
40    echo "Error: failed to open file $filename!\n";
41    exit();
42  }
43
44  rewind($file_handle);
45  /* read entire file and strip tags */
46  echo "-- fgetss() with default length, file pointer at 0 --\n";
47  var_dump( fgetss($file_handle) ); // no length and allowable tags provided, reads entire file
48  var_dump( ftell($file_handle) );
49  var_dump( feof($file_handle) );
50
51  rewind($file_handle);
52  /* read entire file and strip tags tags */
53  echo "-- fgets() with length = 30, file pointer at 0 --\n";
54  var_dump( fgetss($file_handle ,30) ); // length parameter given,not reading entire file
55  var_dump( ftell($file_handle) ); // checking file pointer position initially
56  var_dump( feof($file_handle) ); // confirm file pointer is not at eof
57
58  // close the file
59  fclose($file_handle);
60
61  // delete the file
62  delete_file($filename);
63} // end of for - mode_counter
64
65echo "Done\n";
66?>
67--EXPECT--
68*** Testing fgetss() : Basic operations ***
69
70-- Testing fgetss() with file opened using r mode --
71-- fgetss() with default length, file pointer at 0 --
72string(27) "Testing fgetss() functions
73"
74int(40)
75bool(false)
76-- fgets() with length = 30, file pointer at 0 --
77string(23) "Testing fgetss() functi"
78int(29)
79bool(false)
80
81-- Testing fgetss() with file opened using rb mode --
82-- fgetss() with default length, file pointer at 0 --
83string(27) "Testing fgetss() functions
84"
85int(40)
86bool(false)
87-- fgets() with length = 30, file pointer at 0 --
88string(23) "Testing fgetss() functi"
89int(29)
90bool(false)
91
92-- Testing fgetss() with file opened using rt mode --
93-- fgetss() with default length, file pointer at 0 --
94string(27) "Testing fgetss() functions
95"
96int(40)
97bool(false)
98-- fgets() with length = 30, file pointer at 0 --
99string(23) "Testing fgetss() functi"
100int(29)
101bool(false)
102
103-- Testing fgetss() with file opened using r+ mode --
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 r+b mode --
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 r+t mode --
126-- fgetss() with default length, file pointer at 0 --
127string(27) "Testing fgetss() functions
128"
129int(40)
130bool(false)
131-- fgets() with length = 30, file pointer at 0 --
132string(23) "Testing fgetss() functi"
133int(29)
134bool(false)
135Done
136