1--TEST-- 2Test vsprintf() function : usage variations - hexa formats with hexa values 3--SKIPIF-- 4<?php 5if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); 6?> 7--FILE-- 8<?php 9/* Prototype : string vsprintf(string format, array args) 10 * Description: Return a formatted string 11 * Source code: ext/standard/formatted_print.c 12*/ 13 14/* 15 * Test vsprintf() when different hexa formats and hexa values are passed to 16 * the '$format' and '$args' arguments of the function 17*/ 18 19echo "*** Testing vsprintf() : hexa formats with hexa values ***\n"; 20 21// defining array of different hexa formats 22$formats = array( 23 "%x", 24 "%+x %-x %X", 25 "%lx %Lx, %4x %-4x", 26 "%10.4x %-10.4x %04x %04.4x", 27 "%'#2x %'2x %'$2x %'_2x", 28 "%x %x %x %x", 29 "% %%x x%", 30 '%3$x %4$x %1$x %2$x' 31); 32 33// Arrays of hexa values for the format defined in $format. 34// Each sub array contains hexa values which correspond to each format string in $format 35$args_array = array( 36 array(0x0), 37 array(-0x1, 0x1, +0x22), 38 array(0x7FFFFFFF, -0x7fffffff, +0x7000000, -0x80000000), 39 array(123456, 12345678, -1234567, 1234567), 40 array(1, 0x2222, 0333333, -0x44444444), 41 array(0x123b, 0xfAb, "0xaxz", 012), 42 array(0x1234, 0x34, 0x2ff), 43 array(0x3, 0x4, 0x1, 0x2) 44 45); 46 47// looping to test vsprintf() with different char octal from the above $format array 48// and with octal values from the above $args_array array 49$counter = 1; 50foreach($formats as $format) { 51 echo "\n-- Iteration $counter --\n"; 52 var_dump( vsprintf($format, $args_array[$counter-1]) ); 53 $counter++; 54} 55 56echo "Done"; 57?> 58 59--EXPECTF-- 60*** Testing vsprintf() : hexa formats with hexa values *** 61 62-- Iteration 1 -- 63string(1) "0" 64 65-- Iteration 2 -- 66string(13) "ffffffff 1 22" 67 68-- Iteration 3 -- 69string(28) "7fffffff x, 7000000 80000000" 70 71-- Iteration 4 -- 72string(35) " ffed2979 0000" 73 74-- Iteration 5 -- 75string(22) "#1 2222 1b6db bbbbbbbc" 76 77-- Iteration 6 -- 78string(12) "123b fab 0 a" 79 80-- Iteration 7 -- 81string(5) "%34 x" 82 83-- Iteration 8 -- 84string(7) "1 2 3 4" 85Done 86