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 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; 34 35$filename = __DIR__."/fgetss_basic2.tmp"; 36 37/* try reading the file opened in different modes of reading */ 38$file_modes = array("w+","w+b", "w+t","a+", "a+b", "a+t","x+","x+b","x+t"); 39 40for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { 41 echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n"; 42 43 /* create an empty file and write the strings with tags */ 44 $file_handle = fopen($filename, $file_modes[$mode_counter]); 45 fwrite($file_handle,$string_with_tags); //writing data to the file 46 if(!$file_handle) { 47 echo "Error: failed to open file $filename!\n"; 48 exit(); 49 } 50 51 // rewind the file pointer to beginning of the file 52 var_dump( filesize($filename) ); 53 var_dump( rewind($file_handle) ); 54 var_dump( ftell($file_handle) ); 55 var_dump( feof($file_handle) ); 56 57 /* read entire file and strip tags */ 58 echo "-- fgetss() with default length, file pointer at 0 --\n"; 59 var_dump( fgetss($file_handle) ); // no length and allowable tags provided, reads entire file 60 var_dump( ftell($file_handle) ); 61 var_dump( feof($file_handle) ); 62 63 rewind($file_handle); 64 /* read entire file and strip tags tags */ 65 echo "-- fgets() with length = 30, file pointer at 0 --\n"; 66 var_dump( fgetss($file_handle ,30) ); // length parameter given,not reading entire file 67 var_dump( ftell($file_handle) ); // checking file pointer position initially 68 var_dump( feof($file_handle) ); // confirm file pointer is not at eof 69 70 // close the file 71 fclose($file_handle); 72 73 // delete the file 74 unlink($filename); 75} // end of for - mode_counter 76 77echo "Done\n"; 78?> 79--EXPECT-- 80*** Testing fgetss() : basic operations *** 81 82-- Testing fgetss() with file opened using w+ mode -- 83int(192) 84bool(true) 85int(0) 86bool(false) 87-- fgetss() with default length, file pointer at 0 -- 88string(27) "Testing fgetss() functions 89" 90int(40) 91bool(false) 92-- fgets() with length = 30, file pointer at 0 -- 93string(23) "Testing fgetss() functi" 94int(29) 95bool(false) 96 97-- Testing fgetss() with file opened using w+b mode -- 98int(192) 99bool(true) 100int(0) 101bool(false) 102-- fgetss() with default length, file pointer at 0 -- 103string(27) "Testing fgetss() functions 104" 105int(40) 106bool(false) 107-- fgets() with length = 30, file pointer at 0 -- 108string(23) "Testing fgetss() functi" 109int(29) 110bool(false) 111 112-- Testing fgetss() with file opened using w+t mode -- 113int(192) 114bool(true) 115int(0) 116bool(false) 117-- fgetss() with default length, file pointer at 0 -- 118string(27) "Testing fgetss() functions 119" 120int(40) 121bool(false) 122-- fgets() with length = 30, file pointer at 0 -- 123string(23) "Testing fgetss() functi" 124int(29) 125bool(false) 126 127-- Testing fgetss() with file opened using a+ mode -- 128int(192) 129bool(true) 130int(0) 131bool(false) 132-- fgetss() with default length, file pointer at 0 -- 133string(27) "Testing fgetss() functions 134" 135int(40) 136bool(false) 137-- fgets() with length = 30, file pointer at 0 -- 138string(23) "Testing fgetss() functi" 139int(29) 140bool(false) 141 142-- Testing fgetss() with file opened using a+b mode -- 143int(192) 144bool(true) 145int(0) 146bool(false) 147-- fgetss() with default length, file pointer at 0 -- 148string(27) "Testing fgetss() functions 149" 150int(40) 151bool(false) 152-- fgets() with length = 30, file pointer at 0 -- 153string(23) "Testing fgetss() functi" 154int(29) 155bool(false) 156 157-- Testing fgetss() with file opened using a+t mode -- 158int(192) 159bool(true) 160int(0) 161bool(false) 162-- fgetss() with default length, file pointer at 0 -- 163string(27) "Testing fgetss() functions 164" 165int(40) 166bool(false) 167-- fgets() with length = 30, file pointer at 0 -- 168string(23) "Testing fgetss() functi" 169int(29) 170bool(false) 171 172-- Testing fgetss() with file opened using x+ mode -- 173int(192) 174bool(true) 175int(0) 176bool(false) 177-- fgetss() with default length, file pointer at 0 -- 178string(27) "Testing fgetss() functions 179" 180int(40) 181bool(false) 182-- fgets() with length = 30, file pointer at 0 -- 183string(23) "Testing fgetss() functi" 184int(29) 185bool(false) 186 187-- Testing fgetss() with file opened using x+b mode -- 188int(192) 189bool(true) 190int(0) 191bool(false) 192-- fgetss() with default length, file pointer at 0 -- 193string(27) "Testing fgetss() functions 194" 195int(40) 196bool(false) 197-- fgets() with length = 30, file pointer at 0 -- 198string(23) "Testing fgetss() functi" 199int(29) 200bool(false) 201 202-- Testing fgetss() with file opened using x+t mode -- 203int(192) 204bool(true) 205int(0) 206bool(false) 207-- fgetss() with default length, file pointer at 0 -- 208string(27) "Testing fgetss() functions 209" 210int(40) 211bool(false) 212-- fgets() with length = 30, file pointer at 0 -- 213string(23) "Testing fgetss() functi" 214int(29) 215bool(false) 216Done 217