1--TEST-- 2Test fgetss() function : usage variations - write only modes 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) != 'WIN') { 6 die('skip.. only on 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 39if(substr(PHP_OS, 0, 3) == "WIN") { 40 $string_with_tags = str_replace("\r",'', $string_with_tags); 41} 42 43$filename = dirname(__FILE__)."/fgetss_variation1.tmp"; 44 45/* try reading the file opened in different modes of reading */ 46$file_modes = array("w","wb", "wt","a", "ab", "at","x","xb","xt"); 47 48for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { 49 echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n"; 50 51 /* create an empty file and write the strings with tags */ 52 $file_handle = fopen($filename, $file_modes[$mode_counter]); 53 fwrite($file_handle,$string_with_tags); 54 if(!$file_handle) { 55 echo "Error: failed to open file $filename!\n"; 56 exit(); 57 } 58 59 // rewind the file pointer to beginning of the file 60 var_dump( filesize($filename) ); 61 var_dump( rewind($file_handle) ); 62 var_dump( ftell($file_handle) ); 63 var_dump( feof($file_handle) ); 64 65 /* read entire file and strip tags */ 66 echo "-- fgetss() with default length, file pointer at 0 , expected : no character should be read --\n"; 67 var_dump( fgetss($file_handle) ); // expected : no character should be read 68 var_dump( ftell($file_handle) ); //ensure that file pointer position is not changed 69 var_dump( feof($file_handle) ); // check if end of file pointer is set 70 71 // close the file 72 fclose($file_handle); 73 74 // delete the file 75 delete_file($filename); 76} // end of for - mode_counter 77 78echo "Done\n"; 79?> 80--EXPECT-- 81*** Testing fgetss() : usage variations *** 82 83-- Testing fgetss() with file opened using w mode -- 84int(445) 85bool(true) 86int(0) 87bool(false) 88-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 89bool(false) 90int(0) 91bool(false) 92 93-- Testing fgetss() with file opened using wb mode -- 94int(445) 95bool(true) 96int(0) 97bool(false) 98-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 99bool(false) 100int(0) 101bool(false) 102 103-- Testing fgetss() with file opened using wt mode -- 104int(453) 105bool(true) 106int(0) 107bool(false) 108-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 109bool(false) 110int(0) 111bool(false) 112 113-- Testing fgetss() with file opened using a mode -- 114int(445) 115bool(true) 116int(0) 117bool(false) 118-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 119bool(false) 120int(0) 121bool(false) 122 123-- Testing fgetss() with file opened using ab mode -- 124int(445) 125bool(true) 126int(0) 127bool(false) 128-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 129bool(false) 130int(0) 131bool(false) 132 133-- Testing fgetss() with file opened using at mode -- 134int(453) 135bool(true) 136int(0) 137bool(false) 138-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 139bool(false) 140int(0) 141bool(false) 142 143-- Testing fgetss() with file opened using x mode -- 144int(445) 145bool(true) 146int(0) 147bool(false) 148-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 149bool(false) 150int(0) 151bool(false) 152 153-- Testing fgetss() with file opened using xb mode -- 154int(445) 155bool(true) 156int(0) 157bool(false) 158-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 159bool(false) 160int(0) 161bool(false) 162 163-- Testing fgetss() with file opened using xt mode -- 164int(453) 165bool(true) 166int(0) 167bool(false) 168-- fgetss() with default length, file pointer at 0 , expected : no character should be read -- 169bool(false) 170int(0) 171bool(false) 172Done 173