Return to fprintf_variation_002.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings |
1.1 misho 1: --TEST-- 2: Test fprintf() function (variation - 2) 3: --SKIPIF-- 4: <?php 5: $data_file = dirname(__FILE__) . '/dump.txt'; 6: if (!($fp = fopen($data_file, 'w'))) { 7: die('skip File dump.txt could not be created'); 8: } 9: ?> 10: --FILE-- 11: <?php 12: 13: $int_variation = array( "%d", "%-d", "%+d", "%7.2d", "%-7.2d", "%07.2d", "%-07.2d", "%'#7.2d" ); 14: $int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" ); 15: 16: /* creating dumping file */ 17: $data_file = dirname(__FILE__) . '/dump.txt'; 18: if (!($fp = fopen($data_file, 'wt'))) 19: return; 20: 21: $counter = 1; 22: /* integer type variations */ 23: fprintf($fp, "\n*** Testing fprintf() with integers ***\n"); 24: foreach( $int_variation as $int_var ) { 25: fprintf( $fp, "\n-- Iteration %d --\n",$counter); 26: foreach( $int_numbers as $int_num ) { 27: fprintf( $fp, "\n"); 28: fprintf( $fp, $int_var, $int_num ); 29: } 30: $counter++; 31: } 32: 33: fclose($fp); 34: 35: print_r(file_get_contents($data_file)); 36: echo "\nDone"; 37: 38: unlink($data_file); 39: 40: ?> 41: --EXPECTF-- 42: *** Testing fprintf() with integers *** 43: 44: -- Iteration 1 -- 45: 46: 0 47: 1 48: -1 49: 2 50: -2 51: 23333333 52: -23333333 53: 1234 54: -- Iteration 2 -- 55: 56: 0 57: 1 58: -1 59: 2 60: -2 61: 23333333 62: -23333333 63: 1234 64: -- Iteration 3 -- 65: 66: +0 67: +1 68: -1 69: +2 70: -2 71: +23333333 72: -23333333 73: +1234 74: -- Iteration 4 -- 75: 76: 0 77: 1 78: -1 79: 2 80: -2 81: 23333333 82: -23333333 83: 1234 84: -- Iteration 5 -- 85: 86: 0 87: 1 88: -1 89: 2 90: -2 91: 23333333 92: -23333333 93: 1234 94: -- Iteration 6 -- 95: 96: 0000000 97: 0000001 98: -000001 99: 0000002 100: -000002 101: 23333333 102: -23333333 103: 0001234 104: -- Iteration 7 -- 105: 106: 0 107: 1 108: -1 109: 2 110: -2 111: 23333333 112: -23333333 113: 1234 114: -- Iteration 8 -- 115: 116: ######0 117: ######1 118: #####-1 119: ######2 120: #####-2 121: 23333333 122: -23333333 123: ###1234 124: Done