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