1--TEST-- 2Test vprintf() function : usage variations - string formats with strings 3--FILE-- 4<?php 5 6/* 7 * Test vprintf() when different string formats and string values are passed to 8 * the '$format' and '$args' arguments of the function 9*/ 10 11echo "*** Testing vprintf() : string formats with strings ***\n"; 12 13 14// defining different heredoc strings 15$heredoc_string = <<<EOT 16This is string defined 17using heredoc. 18EOT; 19 20/* heredoc string with only numerics */ 21$heredoc_numeric_string = <<<EOT 22123456 3993 234849 string 24EOT; 25 26/* empty heardoc string */ 27$heredoc_empty_string = <<<EOT 28EOT; 29 30// defining array of string formats 31$formats = array( 32 "%s", 33 "%+s %-s", 34 "%ls %4s %-4s", 35 "%10.4s %-10.4s %04s %04.4s", 36 "%'#2s %'2s %'$2s %'_2s", 37 "%% %%s", 38 '%3$s %4$s %1$s %2$s' 39); 40 41// Arrays of string values for the format defined in $format. 42// Each sub array contains string values which correspond to each format string in $format 43$args_array = array( 44 array(" "), 45 array("hello\0world", "hello\0"), 46 array("@#$%&*", "\x55F", "\001"), 47 array("sunday", 'monday', "tuesday", 'wednesday'), 48 array($heredoc_string, "abcdef", $heredoc_numeric_string, $heredoc_empty_string), 49 array("one", "two", 'three'), 50 array("three", 'four', 'one', "two") 51 52); 53 54// looping to test vprintf() with different string formats from the above $format array 55// and with string from the above $args_array array 56$counter = 1; 57foreach($formats as $format) { 58 echo "\n-- Iteration $counter --\n"; 59 $result = vprintf($format, $args_array[$counter-1]); 60 echo "\n"; 61 var_dump($result); 62 $counter++; 63} 64 65?> 66--EXPECTF-- 67*** Testing vprintf() : string formats with strings *** 68 69-- Iteration 1 -- 70 71int(1) 72 73-- Iteration 2 -- 74hello%0world hello%0 75int(18) 76 77-- Iteration 3 -- 78@#$%&* UF 79int(16) 80 81-- Iteration 4 -- 82 sund mond tuesday wedn 83int(34) 84 85-- Iteration 5 -- 86This is string defined 87using heredoc. abcdef 123456 3993 884849 string __ 89int(71) 90 91-- Iteration 6 -- 92% %s 93int(4) 94 95-- Iteration 7 -- 96one two three four 97int(18) 98