1--TEST-- 2Test vfprintf() function : usage variations - int formats with int values 3--FILE-- 4<?php 5/* Prototype : int vfprintf ( resource $handle , string $format , array $args ) 6 * Description: Write a formatted string to a stream 7 * Source code: ext/standard/formatted_print.c 8*/ 9 10/* 11 * Test vfprintf() when different int formats and int values are passed to 12 * the '$format' and '$args' arguments of the function 13*/ 14 15echo "*** Testing vfprintf() : int formats with int values ***\n"; 16 17 18// defining array of int formats 19$formats = array( 20 "%d", 21 "%+d %-d %D", 22 "%ld %Ld, %4d %-4d", 23 "%10.4d %-10.4d %04d %04.4d", 24 "%'#2d %'2d %'$2d %'_2d", 25 "%d %d %d %d", 26 "% %%d d%", 27 '%3$d %4$d %1$d %2$d' 28); 29 30// Arrays of int values for the format defined in $format. 31// Each sub array contains int values which correspond to each format string in $format 32$args_array = array( 33 array(0), 34 array(-1, 1, +22), 35 array(2147483647, -2147483648, +2147483640, -2147483640), 36 array(123456, 12345678, -1234567, 1234567), 37 array(111, 2222, 333333, 44444444), 38 array(0x123b, 0xfAb, 0123, 012), 39 array(1234, -5678, 2345), 40 array(3, 4, 1, 2) 41 42); 43 44// looping to test vfprintf() with different int formats from the above $format array 45// and with int values from the above $args_array array 46 47/* creating dumping file */ 48$data_file = __DIR__ . '/vfprintf_variation3.txt'; 49if (!($fp = fopen($data_file, 'wt'))) 50 return; 51 52$counter = 1; 53foreach($formats as $format) { 54 fprintf($fp, "\n-- Iteration %d --\n",$counter); 55 vfprintf($fp, $format, $args_array[$counter-1]); 56 $counter++; 57} 58 59fclose($fp); 60print_r(file_get_contents($data_file)); 61echo "\n"; 62 63unlink($data_file); 64 65?> 66===DONE=== 67--EXPECT-- 68*** Testing vfprintf() : int formats with int values *** 69 70-- Iteration 1 -- 710 72-- Iteration 2 -- 73-1 1 74-- Iteration 3 -- 752147483647 d, 2147483640 -2147483640 76-- Iteration 4 -- 77 123456 12345678 -1234567 1234567 78-- Iteration 5 -- 79111 2222 333333 44444444 80-- Iteration 6 -- 814667 4011 83 10 82-- Iteration 7 -- 83%-5678 d 84-- Iteration 8 -- 851 2 3 4 86===DONE=== 87