1--TEST-- 2Test fprintf() function (variation - 2) 3--FILE-- 4<?php 5 6$int_variation = array( "%d", "%-d", "%+d", "%7.2d", "%-7.2d", "%07.2d", "%-07.2d", "%'#7.2d" ); 7$int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" ); 8 9/* creating dumping file */ 10$data_file = __DIR__ . '/fprintf_variation_002.txt'; 11if (!($fp = fopen($data_file, 'wt'))) 12 return; 13 14$counter = 1; 15/* integer type variations */ 16fprintf($fp, "\n*** Testing fprintf() with integers ***\n"); 17foreach( $int_variation as $int_var ) { 18 fprintf( $fp, "\n-- Iteration %d --\n",$counter); 19 foreach( $int_numbers as $int_num ) { 20 fprintf( $fp, "\n"); 21 fprintf( $fp, $int_var, $int_num ); 22 } 23 $counter++; 24} 25 26fclose($fp); 27 28print_r(file_get_contents($data_file)); 29echo "\nDone"; 30 31unlink($data_file); 32 33?> 34--EXPECT-- 35*** Testing fprintf() with integers *** 36 37-- Iteration 1 -- 38 390 401 41-1 422 43-2 4423333333 45-23333333 461234 47-- Iteration 2 -- 48 490 501 51-1 522 53-2 5423333333 55-23333333 561234 57-- Iteration 3 -- 58 59+0 60+1 61-1 62+2 63-2 64+23333333 65-23333333 66+1234 67-- Iteration 4 -- 68 69 0 70 1 71 -1 72 2 73 -2 7423333333 75-23333333 76 1234 77-- Iteration 5 -- 78 790 801 81-1 822 83-2 8423333333 85-23333333 861234 87-- Iteration 6 -- 88 890000000 900000001 91-000001 920000002 93-000002 9423333333 95-23333333 960001234 97-- Iteration 7 -- 98 990 1001 101-1 1022 103-2 10423333333 105-23333333 1061234 107-- Iteration 8 -- 108 109######0 110######1 111#####-1 112######2 113#####-2 11423333333 115-23333333 116###1234 117Done 118