Return to fgetss_basic2-win32.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: Test fgetss() function : Basic functionality - read/write modes 3: --SKIPIF-- 4: <?php 5: if (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 fgetss on files which are opened in read/write modes 17: w+, w+b, w+t, 18: a+, a+b, a+t, 19: x+, x+b, x+t 20: */ 21: 22: 23: echo "*** Testing fgetss() : basic operations ***\n"; 24: 25: /* string with html and php tags */ 26: $string_with_tags = <<<EOT 27: <test>Testing fgetss() functions</test> 28: <?php echo "this string is within php tag"; ?> {;}<{> this 29: is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg> 30: <html> html </html> <?php echo "php"; ?> 31: EOT; 32: if(substr(PHP_OS, 0, 3) == "WIN") { 33: $string_with_tags = str_replace("\r",'', $string_with_tags); 34: } 35: $filename = dirname(__FILE__)."/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: 40: for($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 begining 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: 77: echo "Done\n"; 78: ?> 79: --EXPECTF-- 80: *** Testing fgetss() : basic operations *** 81: 82: -- Testing fgetss() with file opened using w+ mode -- 83: int(192) 84: bool(true) 85: int(0) 86: bool(false) 87: -- fgetss() with default length, file pointer at 0 -- 88: string(27) "Testing fgetss() functions 89: " 90: int(40) 91: bool(false) 92: -- fgets() with length = 30, file pointer at 0 -- 93: string(23) "Testing fgetss() functi" 94: int(29) 95: bool(false) 96: 97: -- Testing fgetss() with file opened using w+b mode -- 98: int(192) 99: bool(true) 100: int(0) 101: bool(false) 102: -- fgetss() with default length, file pointer at 0 -- 103: string(27) "Testing fgetss() functions 104: " 105: int(40) 106: bool(false) 107: -- fgets() with length = 30, file pointer at 0 -- 108: string(23) "Testing fgetss() functi" 109: int(29) 110: bool(false) 111: 112: -- Testing fgetss() with file opened using w+t mode -- 113: int(195) 114: bool(true) 115: int(0) 116: bool(false) 117: -- fgetss() with default length, file pointer at 0 -- 118: string(27) "Testing fgetss() functions 119: " 120: int(40) 121: bool(false) 122: -- fgets() with length = 30, file pointer at 0 -- 123: string(23) "Testing fgetss() functi" 124: int(29) 125: bool(false) 126: 127: -- Testing fgetss() with file opened using a+ mode -- 128: int(192) 129: bool(true) 130: int(0) 131: bool(false) 132: -- fgetss() with default length, file pointer at 0 -- 133: string(27) "Testing fgetss() functions 134: " 135: int(40) 136: bool(false) 137: -- fgets() with length = 30, file pointer at 0 -- 138: string(23) "Testing fgetss() functi" 139: int(29) 140: bool(false) 141: 142: -- Testing fgetss() with file opened using a+b mode -- 143: int(192) 144: bool(true) 145: int(0) 146: bool(false) 147: -- fgetss() with default length, file pointer at 0 -- 148: string(27) "Testing fgetss() functions 149: " 150: int(40) 151: bool(false) 152: -- fgets() with length = 30, file pointer at 0 -- 153: string(23) "Testing fgetss() functi" 154: int(29) 155: bool(false) 156: 157: -- Testing fgetss() with file opened using a+t mode -- 158: int(195) 159: bool(true) 160: int(0) 161: bool(false) 162: -- fgetss() with default length, file pointer at 0 -- 163: string(27) "Testing fgetss() functions 164: " 165: int(40) 166: bool(false) 167: -- fgets() with length = 30, file pointer at 0 -- 168: string(23) "Testing fgetss() functi" 169: int(29) 170: bool(false) 171: 172: -- Testing fgetss() with file opened using x+ mode -- 173: int(192) 174: bool(true) 175: int(0) 176: bool(false) 177: -- fgetss() with default length, file pointer at 0 -- 178: string(27) "Testing fgetss() functions 179: " 180: int(40) 181: bool(false) 182: -- fgets() with length = 30, file pointer at 0 -- 183: string(23) "Testing fgetss() functi" 184: int(29) 185: bool(false) 186: 187: -- Testing fgetss() with file opened using x+b mode -- 188: int(192) 189: bool(true) 190: int(0) 191: bool(false) 192: -- fgetss() with default length, file pointer at 0 -- 193: string(27) "Testing fgetss() functions 194: " 195: int(40) 196: bool(false) 197: -- fgets() with length = 30, file pointer at 0 -- 198: string(23) "Testing fgetss() functi" 199: int(29) 200: bool(false) 201: 202: -- Testing fgetss() with file opened using x+t mode -- 203: int(195) 204: bool(true) 205: int(0) 206: bool(false) 207: -- fgetss() with default length, file pointer at 0 -- 208: string(27) "Testing fgetss() functions 209: " 210: int(40) 211: bool(false) 212: -- fgets() with length = 30, file pointer at 0 -- 213: string(23) "Testing fgetss() functi" 214: int(29) 215: bool(false) 216: Done