1--TEST-- 2Test fgetss() function : usage variations - write only 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 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 fgets on files which are opened in non readable modes 19 w, wb, wt, 20 a, ab, at, 21 x, xb, xt 22*/ 23 24// include the common file related test functions 25include ("file.inc"); 26 27echo "*** Testing fgetss() : usage variations ***\n"; 28 29/* string with html and php tags */ 30$string_with_tags = <<<EOT 31<test>Testing fgetss() functions</test> 32<?php echo "this string is within php tag"; ?> {;}<{> this 33is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg> 34<html> html </html> <?php echo "php"; ?> 35this line is without any html and php tags 36this is a line with more than eighty character,want to check line splitting correctly after 80 characters 37this text contains some html tags <body> body </body> <br> br </br> 38this is the line with \n character. 39EOT; 40 41$filename = dirname(__FILE__)."/fgetss_variation1.tmp"; 42 43/* try reading the file opened in different modes of reading */ 44$file_modes = array("w","wb", "wt","a", "ab", "at","x","xb","xt"); 45 46for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { 47 echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n"; 48 49 /* create an empty file and write the strings with tags */ 50 $file_handle = fopen($filename, $file_modes[$mode_counter]); 51 fwrite($file_handle,$string_with_tags); 52 if(!$file_handle) { 53 echo "Error: failed to open file $filename!\n"; 54 exit(); 55 } 56 57 // rewind the file pointer to beginning of the file 58 var_dump( filesize($filename) ); 59 var_dump( rewind($file_handle) ); 60 var_dump( ftell($file_handle) ); 61 var_dump( feof($file_handle) ); 62 63 /* read entire file and strip tags */ 64 echo "-- fgetss() with default length, file pointer at 0 , expected : no character should be read --\n"; 65 var_dump( fgetss($file_handle) ); // expected : no character should be read 66 var_dump( ftell($file_handle) ); //ensure that file pointer position is not changed 67 var_dump( feof($file_handle) ); // check if end of file pointer is set 68 69 // close the file 70 fclose($file_handle); 71 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 w mode -- 82int(445) 83bool(true) 84int(0) 85bool(false) 86-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 87bool(false) 88int(0) 89bool(false) 90 91-- Testing fgetss() with file opened using wb mode -- 92int(445) 93bool(true) 94int(0) 95bool(false) 96-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 97bool(false) 98int(0) 99bool(false) 100 101-- Testing fgetss() with file opened using wt mode -- 102int(445) 103bool(true) 104int(0) 105bool(false) 106-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 107bool(false) 108int(0) 109bool(false) 110 111-- Testing fgetss() with file opened using a mode -- 112int(445) 113bool(true) 114int(0) 115bool(false) 116-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 117bool(false) 118int(0) 119bool(false) 120 121-- Testing fgetss() with file opened using ab mode -- 122int(445) 123bool(true) 124int(0) 125bool(false) 126-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 127bool(false) 128int(0) 129bool(false) 130 131-- Testing fgetss() with file opened using at mode -- 132int(445) 133bool(true) 134int(0) 135bool(false) 136-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 137bool(false) 138int(0) 139bool(false) 140 141-- Testing fgetss() with file opened using x mode -- 142int(445) 143bool(true) 144int(0) 145bool(false) 146-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 147bool(false) 148int(0) 149bool(false) 150 151-- Testing fgetss() with file opened using xb mode -- 152int(445) 153bool(true) 154int(0) 155bool(false) 156-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 157bool(false) 158int(0) 159bool(false) 160 161-- Testing fgetss() with file opened using xt mode -- 162int(445) 163bool(true) 164int(0) 165bool(false) 166-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 167bool(false) 168int(0) 169bool(false) 170Done 171