1--TEST-- 2Test sprintf() function : usage variations - char formats with char values 3--FILE-- 4<?php 5/* Prototype : string sprintf(string $format [, mixed $arg1 [, mixed ...]]) 6 * Description: Return a formatted string 7 * Source code: ext/standard/formatted_print.c 8*/ 9 10 11echo "*** Testing sprintf() : char formats with char values ***\n"; 12 13// array of char values 14$char_values = array( 'a', "a", 67, -67, 99, ' ', '', 'A', "A" ); 15 16// array of char formats 17$char_formats = array( 18 "%c", "%hc", "%lc", 19 "%Lc", " %c", "%c ", 20 "\t%c", "\n%c", "%4c", 21 "%30c", "%[a-bA-B@#$&]", "%*c" 22); 23 24$count = 1; 25foreach($char_values as $char_value) { 26 echo "\n-- Iteration $count --\n"; 27 28 foreach($char_formats as $format) { 29 var_dump( sprintf($format, $char_value) ); 30 } 31 $count++; 32}; 33 34echo "Done"; 35?> 36--EXPECTF-- 37*** Testing sprintf() : char formats with char values *** 38 39-- Iteration 1 -- 40string(1) "" 41string(1) "c" 42string(1) "" 43string(1) "c" 44string(2) " " 45string(2) " " 46string(2) " " 47string(2) " 48" 49string(1) "" 50string(1) "" 51string(11) "a-bA-B@#$&]" 52string(1) "c" 53 54-- Iteration 2 -- 55string(1) "" 56string(1) "c" 57string(1) "" 58string(1) "c" 59string(2) " " 60string(2) " " 61string(2) " " 62string(2) " 63" 64string(1) "" 65string(1) "" 66string(11) "a-bA-B@#$&]" 67string(1) "c" 68 69-- Iteration 3 -- 70string(1) "C" 71string(1) "c" 72string(1) "C" 73string(1) "c" 74string(2) " C" 75string(2) "C " 76string(2) " C" 77string(2) " 78C" 79string(1) "C" 80string(1) "C" 81string(11) "a-bA-B@#$&]" 82string(1) "c" 83 84-- Iteration 4 -- 85string(1) "�" 86string(1) "c" 87string(1) "�" 88string(1) "c" 89string(2) " �" 90string(2) "� " 91string(2) " �" 92string(2) " 93�" 94string(1) "�" 95string(1) "�" 96string(11) "a-bA-B@#$&]" 97string(1) "c" 98 99-- Iteration 5 -- 100string(1) "c" 101string(1) "c" 102string(1) "c" 103string(1) "c" 104string(2) " c" 105string(2) "c " 106string(2) " c" 107string(2) " 108c" 109string(1) "c" 110string(1) "c" 111string(11) "a-bA-B@#$&]" 112string(1) "c" 113 114-- Iteration 6 -- 115string(1) "" 116string(1) "c" 117string(1) "" 118string(1) "c" 119string(2) " " 120string(2) " " 121string(2) " " 122string(2) " 123" 124string(1) "" 125string(1) "" 126string(11) "a-bA-B@#$&]" 127string(1) "c" 128 129-- Iteration 7 -- 130string(1) "" 131string(1) "c" 132string(1) "" 133string(1) "c" 134string(2) " " 135string(2) " " 136string(2) " " 137string(2) " 138" 139string(1) "" 140string(1) "" 141string(11) "a-bA-B@#$&]" 142string(1) "c" 143 144-- Iteration 8 -- 145string(1) "" 146string(1) "c" 147string(1) "" 148string(1) "c" 149string(2) " " 150string(2) " " 151string(2) " " 152string(2) " 153" 154string(1) "" 155string(1) "" 156string(11) "a-bA-B@#$&]" 157string(1) "c" 158 159-- Iteration 9 -- 160string(1) "" 161string(1) "c" 162string(1) "" 163string(1) "c" 164string(2) " " 165string(2) " " 166string(2) " " 167string(2) " 168" 169string(1) "" 170string(1) "" 171string(11) "a-bA-B@#$&]" 172string(1) "c" 173Done