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