1--TEST-- 2Test fgetss() function : usage variations - read/write modes, file pointer at EOF 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) != 'WIN') { 6 die('skip.. only 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() : usage variations ***\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"; ?> 31this line is without any html and php tags 32this is a line with more than eighty character,want to check line splitting correctly after 80 characters 33this text contains some html tags <body> body </body> <br> br </br> 34this is the line with \n character. 35EOT; 36if(substr(PHP_OS, 0, 3) == "WIN") { 37 $string_with_tags = str_replace("\r",'', $string_with_tags); 38} 39 40$filename = dirname(__FILE__)."/fgetss_variation5.tmp"; 41 42/* try reading the file opened in different modes of reading */ 43$file_modes = array("w+","w+b", "w+t","a+", "a+b", "a+t","x+","x+b","x+t"); 44 45for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { 46 echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n"; 47 48 /* create an empty file and write the strings with tags */ 49 $file_handle = fopen($filename, $file_modes[$mode_counter]); 50 fwrite($file_handle,$string_with_tags); //writing data to the file 51 if(!$file_handle) { 52 echo "Error: failed to open file $filename!\n"; 53 exit(); 54 } 55 // rewind the file pointer to beginning of the file 56 var_dump( filesize($filename) ); 57 var_dump( rewind($file_handle) ); 58 var_dump( ftell($file_handle) ); 59 var_dump( feof($file_handle) ); 60 61 echo "-- Reading when file pointer points to EOF --\n"; 62 var_dump( fseek($file_handle,0,SEEK_END) ); // now file pointer at end 63 var_dump( ftell($file_handle) ); //ensure file pointer at end 64 var_dump( fgetss($file_handle) ); // try to read 65 var_dump( ftell($file_handle) ); // find out file position 66 var_dump( feof($file_handle) ); // ensure that file pointer is at eof 67 68 // now file is at the end try reading with length and allowable tags,expecting false 69 var_dump( fgetss($file_handle, 80, "<test>, <html>, <?>") ); 70 var_dump( ftell($file_handle) ); // find out file position 71 var_dump( feof($file_handle) ); // ensure that file pointer is at eof 72 73 74 // close the file 75 fclose($file_handle); 76 77 // delete the file 78 unlink($filename); 79} // end of for - mode_counter 80 81echo "Done\n"; 82?> 83--EXPECT-- 84*** Testing fgetss() : usage variations *** 85 86-- Testing fgetss() with file opened using w+ mode -- 87int(445) 88bool(true) 89int(0) 90bool(false) 91-- Reading when file pointer points to EOF -- 92int(0) 93int(445) 94bool(false) 95int(445) 96bool(true) 97bool(false) 98int(445) 99bool(true) 100 101-- Testing fgetss() with file opened using w+b mode -- 102int(445) 103bool(true) 104int(0) 105bool(false) 106-- Reading when file pointer points to EOF -- 107int(0) 108int(445) 109bool(false) 110int(445) 111bool(true) 112bool(false) 113int(445) 114bool(true) 115 116-- Testing fgetss() with file opened using w+t mode -- 117int(453) 118bool(true) 119int(0) 120bool(false) 121-- Reading when file pointer points to EOF -- 122int(0) 123int(453) 124bool(false) 125int(453) 126bool(true) 127bool(false) 128int(453) 129bool(true) 130 131-- Testing fgetss() with file opened using a+ mode -- 132int(445) 133bool(true) 134int(0) 135bool(false) 136-- Reading when file pointer points to EOF -- 137int(0) 138int(445) 139bool(false) 140int(445) 141bool(true) 142bool(false) 143int(445) 144bool(true) 145 146-- Testing fgetss() with file opened using a+b mode -- 147int(445) 148bool(true) 149int(0) 150bool(false) 151-- Reading when file pointer points to EOF -- 152int(0) 153int(445) 154bool(false) 155int(445) 156bool(true) 157bool(false) 158int(445) 159bool(true) 160 161-- Testing fgetss() with file opened using a+t mode -- 162int(453) 163bool(true) 164int(0) 165bool(false) 166-- Reading when file pointer points to EOF -- 167int(0) 168int(453) 169bool(false) 170int(453) 171bool(true) 172bool(false) 173int(453) 174bool(true) 175 176-- Testing fgetss() with file opened using x+ mode -- 177int(445) 178bool(true) 179int(0) 180bool(false) 181-- Reading when file pointer points to EOF -- 182int(0) 183int(445) 184bool(false) 185int(445) 186bool(true) 187bool(false) 188int(445) 189bool(true) 190 191-- Testing fgetss() with file opened using x+b mode -- 192int(445) 193bool(true) 194int(0) 195bool(false) 196-- Reading when file pointer points to EOF -- 197int(0) 198int(445) 199bool(false) 200int(445) 201bool(true) 202bool(false) 203int(445) 204bool(true) 205 206-- Testing fgetss() with file opened using x+t mode -- 207int(453) 208bool(true) 209int(0) 210bool(false) 211-- Reading when file pointer points to EOF -- 212int(0) 213int(453) 214bool(false) 215int(453) 216bool(true) 217bool(false) 218int(453) 219bool(true) 220Done 221