Return to fgetss_basic2.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.. 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 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: 33: $filename = dirname(__FILE__)."/fgetss_basic2.tmp"; 34: 35: /* try reading the file opened in different modes of reading */ 36: $file_modes = array("w+","w+b", "w+t","a+", "a+b", "a+t","x+","x+b","x+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: $file_handle = fopen($filename, $file_modes[$mode_counter]); 43: fwrite($file_handle,$string_with_tags); //writing data to the file 44: if(!$file_handle) { 45: echo "Error: failed to open file $filename!\n"; 46: exit(); 47: } 48: 49: // rewind the file pointer to begining of the file 50: var_dump( filesize($filename) ); 51: var_dump( rewind($file_handle) ); 52: var_dump( ftell($file_handle) ); 53: var_dump( feof($file_handle) ); 54: 55: /* read entire file and strip tags */ 56: echo "-- fgetss() with default length, file pointer at 0 --\n"; 57: var_dump( fgetss($file_handle) ); // no length and allowable tags provided, reads entire file 58: var_dump( ftell($file_handle) ); 59: var_dump( feof($file_handle) ); 60: 61: rewind($file_handle); 62: /* read entire file and strip tags tags */ 63: echo "-- fgets() with length = 30, file pointer at 0 --\n"; 64: var_dump( fgetss($file_handle ,30) ); // length parameter given,not reading entire file 65: var_dump( ftell($file_handle) ); // checking file pointer position initially 66: var_dump( feof($file_handle) ); // confirm file pointer is not at eof 67: 68: // close the file 69: fclose($file_handle); 70: 71: // delete the file 72: unlink($filename); 73: } // end of for - mode_counter 74: 75: echo "Done\n"; 76: ?> 77: --EXPECTF-- 78: *** Testing fgetss() : basic operations *** 79: 80: -- Testing fgetss() with file opened using w+ mode -- 81: int(192) 82: bool(true) 83: int(0) 84: bool(false) 85: -- fgetss() with default length, file pointer at 0 -- 86: string(27) "Testing fgetss() functions 87: " 88: int(40) 89: bool(false) 90: -- fgets() with length = 30, file pointer at 0 -- 91: string(23) "Testing fgetss() functi" 92: int(29) 93: bool(false) 94: 95: -- Testing fgetss() with file opened using w+b mode -- 96: int(192) 97: bool(true) 98: int(0) 99: bool(false) 100: -- fgetss() with default length, file pointer at 0 -- 101: string(27) "Testing fgetss() functions 102: " 103: int(40) 104: bool(false) 105: -- fgets() with length = 30, file pointer at 0 -- 106: string(23) "Testing fgetss() functi" 107: int(29) 108: bool(false) 109: 110: -- Testing fgetss() with file opened using w+t mode -- 111: int(192) 112: bool(true) 113: int(0) 114: bool(false) 115: -- fgetss() with default length, file pointer at 0 -- 116: string(27) "Testing fgetss() functions 117: " 118: int(40) 119: bool(false) 120: -- fgets() with length = 30, file pointer at 0 -- 121: string(23) "Testing fgetss() functi" 122: int(29) 123: bool(false) 124: 125: -- Testing fgetss() with file opened using a+ mode -- 126: int(192) 127: bool(true) 128: int(0) 129: bool(false) 130: -- fgetss() with default length, file pointer at 0 -- 131: string(27) "Testing fgetss() functions 132: " 133: int(40) 134: bool(false) 135: -- fgets() with length = 30, file pointer at 0 -- 136: string(23) "Testing fgetss() functi" 137: int(29) 138: bool(false) 139: 140: -- Testing fgetss() with file opened using a+b mode -- 141: int(192) 142: bool(true) 143: int(0) 144: bool(false) 145: -- fgetss() with default length, file pointer at 0 -- 146: string(27) "Testing fgetss() functions 147: " 148: int(40) 149: bool(false) 150: -- fgets() with length = 30, file pointer at 0 -- 151: string(23) "Testing fgetss() functi" 152: int(29) 153: bool(false) 154: 155: -- Testing fgetss() with file opened using a+t mode -- 156: int(192) 157: bool(true) 158: int(0) 159: bool(false) 160: -- fgetss() with default length, file pointer at 0 -- 161: string(27) "Testing fgetss() functions 162: " 163: int(40) 164: bool(false) 165: -- fgets() with length = 30, file pointer at 0 -- 166: string(23) "Testing fgetss() functi" 167: int(29) 168: bool(false) 169: 170: -- Testing fgetss() with file opened using x+ mode -- 171: int(192) 172: bool(true) 173: int(0) 174: bool(false) 175: -- fgetss() with default length, file pointer at 0 -- 176: string(27) "Testing fgetss() functions 177: " 178: int(40) 179: bool(false) 180: -- fgets() with length = 30, file pointer at 0 -- 181: string(23) "Testing fgetss() functi" 182: int(29) 183: bool(false) 184: 185: -- Testing fgetss() with file opened using x+b mode -- 186: int(192) 187: bool(true) 188: int(0) 189: bool(false) 190: -- fgetss() with default length, file pointer at 0 -- 191: string(27) "Testing fgetss() functions 192: " 193: int(40) 194: bool(false) 195: -- fgets() with length = 30, file pointer at 0 -- 196: string(23) "Testing fgetss() functi" 197: int(29) 198: bool(false) 199: 200: -- Testing fgetss() with file opened using x+t mode -- 201: int(192) 202: bool(true) 203: int(0) 204: bool(false) 205: -- fgetss() with default length, file pointer at 0 -- 206: string(27) "Testing fgetss() functions 207: " 208: int(40) 209: bool(false) 210: -- fgets() with length = 30, file pointer at 0 -- 211: string(23) "Testing fgetss() functi" 212: int(29) 213: bool(false) 214: Done