1--TEST-- 2Test fprintf() function (variation - 1) 3--SKIPIF-- 4<?php 5$data_file = dirname(__FILE__) . '/dump.txt'; 6if (!($fp = fopen($data_file, 'w'))) { 7 die('skip File dump.txt could not be created'); 8} 9?> 10--FILE-- 11<?php 12 13$float_variation = array( "%f","%-f", "%+f", "%7.2f", "%-7.2f", "%07.2f", "%-07.2f", "%'#7.2f" ); 14$float_numbers = array( 0, 1, -1, 0.32, -0.32, 3.4. -3.4, 2.54, -2.54 ); 15 16/* creating dumping file */ 17$data_file = dirname(__FILE__) . '/dump.txt'; 18if (!($fp = fopen($data_file, 'wt'))) 19 return; 20 21$counter = 1; 22/* float type variations */ 23fprintf($fp, "\n*** Testing fprintf() with floats ***\n"); 24 25foreach( $float_variation as $float_var ) { 26 fprintf( $fp, "\n-- Iteration %d --\n",$counter); 27 foreach( $float_numbers as $float_num ) { 28 fprintf( $fp, "\n"); 29 fprintf( $fp, $float_var, $float_num ); 30 } 31 $counter++; 32} 33 34fclose($fp); 35print_r(file_get_contents($data_file)); 36echo "\nDone"; 37 38unlink($data_file); 39 40?> 41--EXPECTF-- 42*** Testing fprintf() with floats *** 43 44-- Iteration 1 -- 45 460.000000 471.000000 48-1.000000 490.320000 50-0.320000 513.400000 522.540000 53-2.540000 54-- Iteration 2 -- 55 560.000000 571.000000 58-1.000000 590.320000 60-0.320000 613.400000 622.540000 63-2.540000 64-- Iteration 3 -- 65 66+0.000000 67+1.000000 68-1.000000 69+0.320000 70-0.320000 71+3.400000 72+2.540000 73-2.540000 74-- Iteration 4 -- 75 76 0.00 77 1.00 78 -1.00 79 0.32 80 -0.32 81 3.40 82 2.54 83 -2.54 84-- Iteration 5 -- 85 860.00 871.00 88-1.00 890.32 90-0.32 913.40 922.54 93-2.54 94-- Iteration 6 -- 95 960000.00 970001.00 98-001.00 990000.32 100-000.32 1010003.40 1020002.54 103-002.54 104-- Iteration 7 -- 105 1060.00000 1071.00000 108-1.0000 1090.32000 110-0.3200 1113.40000 1122.54000 113-2.5400 114-- Iteration 8 -- 115 116###0.00 117###1.00 118##-1.00 119###0.32 120##-0.32 121###3.40 122###2.54 123##-2.54 124Done 125