Return to fscanf_variation44.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 - unsigned formats with boolean 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 scan boolean data using different unsigned format types */ 12: 13: $file_path = dirname(__FILE__); 14: 15: echo "*** Test fscanf(): different unsigned format types with boolean data ***\n"; 16: 17: // create a file 18: $filename = "$file_path/fscanf_variation44.tmp"; 19: $file_handle = fopen($filename, "w"); 20: if($file_handle == false) 21: exit("Error:failed to open file $filename"); 22: 23: // array of boolean types 24: $bool_types = array ( 25: true, 26: false, 27: TRUE, 28: FALSE, 29: ); 30: 31: $unsigned_formats = array( "%u", "%hu", "%lu", "%Lu", " %u", "%u ", "% u", "\t%u", "\n%u", "%4u", "%30u", "%[0-9]", "%*u"); 32: 33: $counter = 1; 34: 35: // writing to the file 36: foreach($bool_types as $value) { 37: @fprintf($file_handle, $value); 38: @fprintf($file_handle, "\n"); 39: } 40: // closing the file 41: fclose($file_handle); 42: 43: // opening the file for reading 44: $file_handle = fopen($filename, "r"); 45: if($file_handle == false) { 46: exit("Error:failed to open file $filename"); 47: } 48: 49: $counter = 1; 50: // reading the values from file using different unsigned formats 51: foreach($unsigned_formats as $unsigned_format) { 52: // rewind the file so that for every foreach iteration the file pointer starts from bof 53: rewind($file_handle); 54: echo "\n-- iteration $counter --\n"; 55: while( !feof($file_handle) ) { 56: var_dump( fscanf($file_handle,$unsigned_format) ); 57: } 58: $counter++; 59: } 60: 61: echo "\n*** Done ***"; 62: ?> 63: --CLEAN-- 64: <?php 65: $file_path = dirname(__FILE__); 66: $filename = "$file_path/fscanf_variation44.tmp"; 67: unlink($filename); 68: ?> 69: --EXPECTF-- 70: *** Test fscanf(): different unsigned format types with boolean data *** 71: 72: -- iteration 1 -- 73: array(1) { 74: [0]=> 75: int(1) 76: } 77: NULL 78: array(1) { 79: [0]=> 80: int(1) 81: } 82: NULL 83: bool(false) 84: 85: -- iteration 2 -- 86: array(1) { 87: [0]=> 88: int(1) 89: } 90: NULL 91: array(1) { 92: [0]=> 93: int(1) 94: } 95: NULL 96: bool(false) 97: 98: -- iteration 3 -- 99: array(1) { 100: [0]=> 101: int(1) 102: } 103: NULL 104: array(1) { 105: [0]=> 106: int(1) 107: } 108: NULL 109: bool(false) 110: 111: -- iteration 4 -- 112: array(1) { 113: [0]=> 114: int(1) 115: } 116: NULL 117: array(1) { 118: [0]=> 119: int(1) 120: } 121: NULL 122: bool(false) 123: 124: -- iteration 5 -- 125: array(1) { 126: [0]=> 127: int(1) 128: } 129: NULL 130: array(1) { 131: [0]=> 132: int(1) 133: } 134: NULL 135: bool(false) 136: 137: -- iteration 6 -- 138: array(1) { 139: [0]=> 140: int(1) 141: } 142: NULL 143: array(1) { 144: [0]=> 145: int(1) 146: } 147: NULL 148: bool(false) 149: 150: -- iteration 7 -- 151: 152: Warning: fscanf(): Bad scan conversion character " " in %s on line %d 153: NULL 154: 155: Warning: fscanf(): Bad scan conversion character " " in %s on line %d 156: NULL 157: 158: Warning: fscanf(): Bad scan conversion character " " in %s on line %d 159: NULL 160: 161: Warning: fscanf(): Bad scan conversion character " " in %s on line %d 162: NULL 163: bool(false) 164: 165: -- iteration 8 -- 166: array(1) { 167: [0]=> 168: int(1) 169: } 170: NULL 171: array(1) { 172: [0]=> 173: int(1) 174: } 175: NULL 176: bool(false) 177: 178: -- iteration 9 -- 179: array(1) { 180: [0]=> 181: int(1) 182: } 183: NULL 184: array(1) { 185: [0]=> 186: int(1) 187: } 188: NULL 189: bool(false) 190: 191: -- iteration 10 -- 192: array(1) { 193: [0]=> 194: int(1) 195: } 196: NULL 197: array(1) { 198: [0]=> 199: int(1) 200: } 201: NULL 202: bool(false) 203: 204: -- iteration 11 -- 205: array(1) { 206: [0]=> 207: int(1) 208: } 209: NULL 210: array(1) { 211: [0]=> 212: int(1) 213: } 214: NULL 215: bool(false) 216: 217: -- iteration 12 -- 218: array(1) { 219: [0]=> 220: string(1) "1" 221: } 222: array(1) { 223: [0]=> 224: NULL 225: } 226: array(1) { 227: [0]=> 228: string(1) "1" 229: } 230: array(1) { 231: [0]=> 232: NULL 233: } 234: bool(false) 235: 236: -- iteration 13 -- 237: array(0) { 238: } 239: NULL 240: array(0) { 241: } 242: NULL 243: bool(false) 244: 245: *** Done *** 246: