Return to fgetss_variation4.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: Test fgetss() function : usage variations - read modes, file pointer at EOF 3: --SKIPIF-- 4: <?php 5: if(substr(PHP_OS, 0, 3) == "WIN") 6: die("skip not for Windows"); 7: ?> 8: --FILE-- 9: <?php 10: /* 11: Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] ); 12: Description: Gets line from file pointer and strip HTML tags 13: */ 14: 15: // include the common file related test functions 16: include ("file.inc"); 17: 18: echo "*** Testing fgetss() : usage variations ***\n"; 19: 20: /* string with html and php tags */ 21: $string_with_tags = <<<EOT 22: <test>Testing fgetss() functions</test> 23: <?php echo "this string is within php tag"; ?> {;}<{> this 24: is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg> 25: <html> html </html> <?php echo "php"; ?> 26: this line is without any html and php tags 27: this is a line with more than eighty character,want to check line splitting correctly after 80 characters 28: this is the text containing \r character 29: this text contains some html tags <body> body </body> <br> br </br> 30: this is the line with \n character. 31: EOT; 32: 33: $filename = dirname(__FILE__)."/fgetss_variation4.tmp"; 34: 35: /* try reading the file opened in different modes of reading */ 36: $file_modes = array("r","rb", "rt","r+", "r+b", "r+t"); 37: 38: for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { 39: echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n"; 40: 41: /* create an empty file and write the strings with tags */ 42: create_file ($filename); //create an empty file 43: file_put_contents($filename, $string_with_tags); 44: $file_handle = fopen($filename, $file_modes[$mode_counter]); 45: if(!$file_handle) { 46: echo "Error: failed to open file $filename!\n"; 47: exit(); 48: } 49: 50: // rewind the file pointer to begining of the file 51: var_dump( filesize($filename) ); 52: var_dump( rewind($file_handle) ); 53: var_dump( ftell($file_handle) ); 54: var_dump( feof($file_handle) ); 55: 56: echo "-- Reading when file pointer points to EOF --\n"; 57: var_dump( fseek($file_handle,0,SEEK_END) ); // now file pointer at end 58: var_dump( ftell($file_handle) ); //ensure file pointer at end 59: var_dump( fgetss($file_handle) ); // try to read 60: var_dump( ftell($file_handle) ); // find out file position 61: var_dump( feof($file_handle) ); // ensure that file pointer is at eof 62: 63: // now file is at the end try reading with length and allowable tags,expecting false 64: var_dump( fgetss($file_handle, 80, "<test>, <html>, <?>") ); 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: // close the file 69: fclose($file_handle); 70: // delete the file 71: delete_file($filename); 72: } // end of for - mode_counter 73: 74: echo "Done\n"; 75: ?> 76: --EXPECTF-- 77: *** Testing fgetss() : usage variations *** 78: 79: -- Testing fgetss() with file opened using r mode -- 80: int(486) 81: bool(true) 82: int(0) 83: bool(false) 84: -- Reading when file pointer points to EOF -- 85: int(0) 86: int(486) 87: bool(false) 88: int(486) 89: bool(true) 90: bool(false) 91: int(486) 92: bool(true) 93: 94: -- Testing fgetss() with file opened using rb mode -- 95: int(486) 96: bool(true) 97: int(0) 98: bool(false) 99: -- Reading when file pointer points to EOF -- 100: int(0) 101: int(486) 102: bool(false) 103: int(486) 104: bool(true) 105: bool(false) 106: int(486) 107: bool(true) 108: 109: -- Testing fgetss() with file opened using rt mode -- 110: int(486) 111: bool(true) 112: int(0) 113: bool(false) 114: -- Reading when file pointer points to EOF -- 115: int(0) 116: int(486) 117: bool(false) 118: int(486) 119: bool(true) 120: bool(false) 121: int(486) 122: bool(true) 123: 124: -- Testing fgetss() with file opened using r+ mode -- 125: int(486) 126: bool(true) 127: int(0) 128: bool(false) 129: -- Reading when file pointer points to EOF -- 130: int(0) 131: int(486) 132: bool(false) 133: int(486) 134: bool(true) 135: bool(false) 136: int(486) 137: bool(true) 138: 139: -- Testing fgetss() with file opened using r+b mode -- 140: int(486) 141: bool(true) 142: int(0) 143: bool(false) 144: -- Reading when file pointer points to EOF -- 145: int(0) 146: int(486) 147: bool(false) 148: int(486) 149: bool(true) 150: bool(false) 151: int(486) 152: bool(true) 153: 154: -- Testing fgetss() with file opened using r+t mode -- 155: int(486) 156: bool(true) 157: int(0) 158: bool(false) 159: -- Reading when file pointer points to EOF -- 160: int(0) 161: int(486) 162: bool(false) 163: int(486) 164: bool(true) 165: bool(false) 166: int(486) 167: bool(true) 168: Done