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