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