Return to fscanf_variation53.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: Test fscanf() function: usage variations - file pointer pointing to EOF 3: --FILE-- 4: <?php 5: 6: /* 7: Prototype: mixed fscanf ( resource $handle, string $format [, mixed &$...] ); 8: Description: Parses input from a file according to a format 9: */ 10: 11: /* Test fscanf() to read a file when file pointer is pointing to EOF */ 12: 13: $file_path = dirname(__FILE__); 14: 15: echo "*** Test fscanf(): to read a file when file pointer is pointing to EOF ***\n"; 16: 17: // various formats 18: $formats = array( "%d", "%f", "%e", "%u", " %s", "%x", "%o"); 19: 20: $counter = 1; 21: 22: // various read modes 23: $modes = array("r", "rb", "rt", "r+", "r+b", "r+t", 24: "w+", "w+b", "w+t", 25: "a+", "a+b", "a+t" 26: ); 27: 28: $counter = 1; 29: // reading the values from file using different integer formats 30: foreach($modes as $mode) { 31: 32: // create an empty file 33: $filename = "$file_path/fscanf_variation52.tmp"; 34: $file_handle = fopen($filename, "w"); 35: if($file_handle == false) 36: exit("Error:failed to open file $filename"); 37: 38: //writing data to the file 39: @fwrite($file_handle, "Sample text\n"); 40: 41: // writing a blank line 42: @fwrite($file_handle, "\n"); 43: 44: //closing the file 45: fclose($file_handle); 46: 47: // opening file in $mode mode 48: $file_handle = fopen($filename, $mode); 49: if($file_handle == false) { 50: exit("Error:failed to open file $filename"); 51: } 52: echo "\n-- iteration $counter --\n"; 53: 54: // current location 55: var_dump( ftell($file_handle) ); 56: 57: // set the file pointer to eof 58: var_dump( fseek($file_handle, 0, SEEK_END) ); 59: 60: // current location 61: var_dump( ftell($file_handle) ); 62: 63: foreach($formats as $format) { 64: var_dump( fscanf($file_handle,$format) ); 65: } 66: $counter++; 67: fclose($file_handle); 68: unlink($filename); 69: } 70: 71: echo "\n*** Done ***"; 72: ?> 73: --CLEAN-- 74: <?php 75: $file_path = dirname(__FILE__); 76: $filename = "$file_path/fscanf_variation53.tmp"; 77: if(file_exists($filename)) { 78: unlink($filename); 79: } 80: ?> 81: --EXPECT-- 82: *** Test fscanf(): to read a file when file pointer is pointing to EOF *** 83: 84: -- iteration 1 -- 85: int(0) 86: int(0) 87: int(13) 88: bool(false) 89: bool(false) 90: bool(false) 91: bool(false) 92: bool(false) 93: bool(false) 94: bool(false) 95: 96: -- iteration 2 -- 97: int(0) 98: int(0) 99: int(13) 100: bool(false) 101: bool(false) 102: bool(false) 103: bool(false) 104: bool(false) 105: bool(false) 106: bool(false) 107: 108: -- iteration 3 -- 109: int(0) 110: int(0) 111: int(13) 112: bool(false) 113: bool(false) 114: bool(false) 115: bool(false) 116: bool(false) 117: bool(false) 118: bool(false) 119: 120: -- iteration 4 -- 121: int(0) 122: int(0) 123: int(13) 124: bool(false) 125: bool(false) 126: bool(false) 127: bool(false) 128: bool(false) 129: bool(false) 130: bool(false) 131: 132: -- iteration 5 -- 133: int(0) 134: int(0) 135: int(13) 136: bool(false) 137: bool(false) 138: bool(false) 139: bool(false) 140: bool(false) 141: bool(false) 142: bool(false) 143: 144: -- iteration 6 -- 145: int(0) 146: int(0) 147: int(13) 148: bool(false) 149: bool(false) 150: bool(false) 151: bool(false) 152: bool(false) 153: bool(false) 154: bool(false) 155: 156: -- iteration 7 -- 157: int(0) 158: int(0) 159: int(0) 160: bool(false) 161: bool(false) 162: bool(false) 163: bool(false) 164: bool(false) 165: bool(false) 166: bool(false) 167: 168: -- iteration 8 -- 169: int(0) 170: int(0) 171: int(0) 172: bool(false) 173: bool(false) 174: bool(false) 175: bool(false) 176: bool(false) 177: bool(false) 178: bool(false) 179: 180: -- iteration 9 -- 181: int(0) 182: int(0) 183: int(0) 184: bool(false) 185: bool(false) 186: bool(false) 187: bool(false) 188: bool(false) 189: bool(false) 190: bool(false) 191: 192: -- iteration 10 -- 193: int(0) 194: int(0) 195: int(13) 196: bool(false) 197: bool(false) 198: bool(false) 199: bool(false) 200: bool(false) 201: bool(false) 202: bool(false) 203: 204: -- iteration 11 -- 205: int(0) 206: int(0) 207: int(13) 208: bool(false) 209: bool(false) 210: bool(false) 211: bool(false) 212: bool(false) 213: bool(false) 214: bool(false) 215: 216: -- iteration 12 -- 217: int(0) 218: int(0) 219: int(13) 220: bool(false) 221: bool(false) 222: bool(false) 223: bool(false) 224: bool(false) 225: bool(false) 226: bool(false) 227: 228: *** Done *** 229: