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