1--TEST-- 2Test sprintf() function : usage variations - string formats with string values 3--FILE-- 4<?php 5echo "*** Testing sprintf() : string formats with string values ***\n"; 6 7// defining different heredoc strings 8/* string created using Heredoc (<<<) */ 9$heredoc_string = <<<EOT 10This is string defined 11using heredoc. 12EOT; 13 14/* heredoc string with only numerics */ 15$heredoc_numeric_string = <<<EOT 16123456 3993 174849 string 18EOT; 19 20/* null heardoc string */ 21$heredoc_empty_string = <<<EOT 22EOT; 23$heredoc_null_string = <<<EOT 24NULL 25EOT; 26 27// array of strings used to test the function 28$string_values = array( 29 "", 30 " ", 31 '', 32 ' ', 33 "string", 34 'string', 35 "NULL", 36 'null', 37 "FALSE", 38 'true', 39 "\x0b", 40 "\0", 41 '\0', 42 '\060', 43 "\070", 44 "0x55F", 45 "055", 46 "@#$#$%%$^^$%^%^$^&", 47 $heredoc_string, 48 $heredoc_numeric_string, 49 $heredoc_empty_string, 50 $heredoc_null_string 51); 52 53// array of string formats 54$string_formats = array( 55 "%s", "%ls", " %s", "%s ", 56 "\t%s", "\n%s", "%4s", "%30s", 57); 58 59$count = 1; 60foreach($string_values as $string_value) { 61 echo "\n-- Iteration $count --\n"; 62 63 foreach($string_formats as $format) { 64 var_dump( sprintf($format, $string_value) ); 65 } 66 $count++; 67}; 68 69echo "Done"; 70?> 71--EXPECTF-- 72*** Testing sprintf() : string formats with string values *** 73 74-- Iteration 1 -- 75string(0) "" 76string(0) "" 77string(1) " " 78string(1) " " 79string(1) " " 80string(1) " 81" 82string(4) " " 83string(30) " " 84 85-- Iteration 2 -- 86string(1) " " 87string(1) " " 88string(2) " " 89string(2) " " 90string(2) " " 91string(2) " 92 " 93string(4) " " 94string(30) " " 95 96-- Iteration 3 -- 97string(0) "" 98string(0) "" 99string(1) " " 100string(1) " " 101string(1) " " 102string(1) " 103" 104string(4) " " 105string(30) " " 106 107-- Iteration 4 -- 108string(1) " " 109string(1) " " 110string(2) " " 111string(2) " " 112string(2) " " 113string(2) " 114 " 115string(4) " " 116string(30) " " 117 118-- Iteration 5 -- 119string(6) "string" 120string(6) "string" 121string(7) " string" 122string(7) "string " 123string(7) " string" 124string(7) " 125string" 126string(6) "string" 127string(30) " string" 128 129-- Iteration 6 -- 130string(6) "string" 131string(6) "string" 132string(7) " string" 133string(7) "string " 134string(7) " string" 135string(7) " 136string" 137string(6) "string" 138string(30) " string" 139 140-- Iteration 7 -- 141string(4) "NULL" 142string(4) "NULL" 143string(5) " NULL" 144string(5) "NULL " 145string(5) " NULL" 146string(5) " 147NULL" 148string(4) "NULL" 149string(30) " NULL" 150 151-- Iteration 8 -- 152string(4) "null" 153string(4) "null" 154string(5) " null" 155string(5) "null " 156string(5) " null" 157string(5) " 158null" 159string(4) "null" 160string(30) " null" 161 162-- Iteration 9 -- 163string(5) "FALSE" 164string(5) "FALSE" 165string(6) " FALSE" 166string(6) "FALSE " 167string(6) " FALSE" 168string(6) " 169FALSE" 170string(5) "FALSE" 171string(30) " FALSE" 172 173-- Iteration 10 -- 174string(4) "true" 175string(4) "true" 176string(5) " true" 177string(5) "true " 178string(5) " true" 179string(5) " 180true" 181string(4) "true" 182string(30) " true" 183 184-- Iteration 11 -- 185string(1) "" 186string(1) "" 187string(2) " " 188string(2) " " 189string(2) " " 190string(2) " 191" 192string(4) " " 193string(30) " " 194 195-- Iteration 12 -- 196string(1) "%0" 197string(1) "%0" 198string(2) " %0" 199string(2) "%0 " 200string(2) " %0" 201string(2) " 202%0" 203string(4) " %0" 204string(30) " %0" 205 206-- Iteration 13 -- 207string(2) "\0" 208string(2) "\0" 209string(3) " \0" 210string(3) "\0 " 211string(3) " \0" 212string(3) " 213\0" 214string(4) " \0" 215string(30) " \0" 216 217-- Iteration 14 -- 218string(4) "\060" 219string(4) "\060" 220string(5) " \060" 221string(5) "\060 " 222string(5) " \060" 223string(5) " 224\060" 225string(4) "\060" 226string(30) " \060" 227 228-- Iteration 15 -- 229string(1) "8" 230string(1) "8" 231string(2) " 8" 232string(2) "8 " 233string(2) " 8" 234string(2) " 2358" 236string(4) " 8" 237string(30) " 8" 238 239-- Iteration 16 -- 240string(5) "0x55F" 241string(5) "0x55F" 242string(6) " 0x55F" 243string(6) "0x55F " 244string(6) " 0x55F" 245string(6) " 2460x55F" 247string(5) "0x55F" 248string(30) " 0x55F" 249 250-- Iteration 17 -- 251string(3) "055" 252string(3) "055" 253string(4) " 055" 254string(4) "055 " 255string(4) " 055" 256string(4) " 257055" 258string(4) " 055" 259string(30) " 055" 260 261-- Iteration 18 -- 262string(18) "@#$#$%%$^^$%^%^$^&" 263string(18) "@#$#$%%$^^$%^%^$^&" 264string(19) " @#$#$%%$^^$%^%^$^&" 265string(19) "@#$#$%%$^^$%^%^$^& " 266string(19) " @#$#$%%$^^$%^%^$^&" 267string(19) " 268@#$#$%%$^^$%^%^$^&" 269string(18) "@#$#$%%$^^$%^%^$^&" 270string(30) " @#$#$%%$^^$%^%^$^&" 271 272-- Iteration 19 -- 273string(37) "This is string defined 274using heredoc." 275string(37) "This is string defined 276using heredoc." 277string(38) " This is string defined 278using heredoc." 279string(38) "This is string defined 280using heredoc. " 281string(38) " This is string defined 282using heredoc." 283string(38) " 284This is string defined 285using heredoc." 286string(37) "This is string defined 287using heredoc." 288string(37) "This is string defined 289using heredoc." 290 291-- Iteration 20 -- 292string(23) "123456 3993 2934849 string" 294string(23) "123456 3993 2954849 string" 296string(24) " 123456 3993 2974849 string" 298string(24) "123456 3993 2994849 string " 300string(24) " 123456 3993 3014849 string" 302string(24) " 303123456 3993 3044849 string" 305string(23) "123456 3993 3064849 string" 307string(30) " 123456 3993 3084849 string" 309 310-- Iteration 21 -- 311string(0) "" 312string(0) "" 313string(1) " " 314string(1) " " 315string(1) " " 316string(1) " 317" 318string(4) " " 319string(30) " " 320 321-- Iteration 22 -- 322string(4) "NULL" 323string(4) "NULL" 324string(5) " NULL" 325string(5) "NULL " 326string(5) " NULL" 327string(5) " 328NULL" 329string(4) "NULL" 330string(30) " NULL" 331Done 332