1--TEST-- 2Test sprintf() function : usage variations - octal formats with string 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 10echo "*** Testing sprintf() : octal formats with string values ***\n"; 11 12// array of string values 13$string_values = array( 14 "", 15 '', 16 "0", 17 '0', 18 "1", 19 '1', 20 "0123", 21 "\x01", 22 '\x01', 23 "\01", 24 '\01', 25 'string', 26 "string", 27 "true", 28 "FALSE", 29 'false', 30 'TRUE', 31 "NULL", 32 'null' 33); 34 35// array of octal formats 36$octal_formats = array( 37 "%o", "%ho", "%lo", 38 "%Lo", " %o", "%o ", 39 "\t%o", "\n%o", "%4o", 40 "%30o", "%[0-7]", "%*o" 41); 42 43$count = 1; 44foreach($string_values as $string_value) { 45 echo "\n-- Iteration $count --\n"; 46 47 foreach($octal_formats as $format) { 48 var_dump( sprintf($format, $string_value) ); 49 } 50 $count++; 51}; 52 53echo "Done"; 54?> 55--EXPECTF-- 56*** Testing sprintf() : octal formats with string values *** 57 58-- Iteration 1 -- 59string(1) "0" 60string(1) "o" 61string(1) "0" 62string(1) "o" 63string(2) " 0" 64string(2) "0 " 65string(2) " 0" 66string(2) " 670" 68string(4) " 0" 69string(30) " 0" 70string(4) "0-7]" 71string(1) "o" 72 73-- Iteration 2 -- 74string(1) "0" 75string(1) "o" 76string(1) "0" 77string(1) "o" 78string(2) " 0" 79string(2) "0 " 80string(2) " 0" 81string(2) " 820" 83string(4) " 0" 84string(30) " 0" 85string(4) "0-7]" 86string(1) "o" 87 88-- Iteration 3 -- 89string(1) "0" 90string(1) "o" 91string(1) "0" 92string(1) "o" 93string(2) " 0" 94string(2) "0 " 95string(2) " 0" 96string(2) " 970" 98string(4) " 0" 99string(30) " 0" 100string(4) "0-7]" 101string(1) "o" 102 103-- Iteration 4 -- 104string(1) "0" 105string(1) "o" 106string(1) "0" 107string(1) "o" 108string(2) " 0" 109string(2) "0 " 110string(2) " 0" 111string(2) " 1120" 113string(4) " 0" 114string(30) " 0" 115string(4) "0-7]" 116string(1) "o" 117 118-- Iteration 5 -- 119string(1) "1" 120string(1) "o" 121string(1) "1" 122string(1) "o" 123string(2) " 1" 124string(2) "1 " 125string(2) " 1" 126string(2) " 1271" 128string(4) " 1" 129string(30) " 1" 130string(4) "0-7]" 131string(1) "o" 132 133-- Iteration 6 -- 134string(1) "1" 135string(1) "o" 136string(1) "1" 137string(1) "o" 138string(2) " 1" 139string(2) "1 " 140string(2) " 1" 141string(2) " 1421" 143string(4) " 1" 144string(30) " 1" 145string(4) "0-7]" 146string(1) "o" 147 148-- Iteration 7 -- 149string(3) "173" 150string(1) "o" 151string(3) "173" 152string(1) "o" 153string(4) " 173" 154string(4) "173 " 155string(4) " 173" 156string(4) " 157173" 158string(4) " 173" 159string(30) " 173" 160string(4) "0-7]" 161string(1) "o" 162 163-- Iteration 8 -- 164string(1) "0" 165string(1) "o" 166string(1) "0" 167string(1) "o" 168string(2) " 0" 169string(2) "0 " 170string(2) " 0" 171string(2) " 1720" 173string(4) " 0" 174string(30) " 0" 175string(4) "0-7]" 176string(1) "o" 177 178-- Iteration 9 -- 179string(1) "0" 180string(1) "o" 181string(1) "0" 182string(1) "o" 183string(2) " 0" 184string(2) "0 " 185string(2) " 0" 186string(2) " 1870" 188string(4) " 0" 189string(30) " 0" 190string(4) "0-7]" 191string(1) "o" 192 193-- Iteration 10 -- 194string(1) "0" 195string(1) "o" 196string(1) "0" 197string(1) "o" 198string(2) " 0" 199string(2) "0 " 200string(2) " 0" 201string(2) " 2020" 203string(4) " 0" 204string(30) " 0" 205string(4) "0-7]" 206string(1) "o" 207 208-- Iteration 11 -- 209string(1) "0" 210string(1) "o" 211string(1) "0" 212string(1) "o" 213string(2) " 0" 214string(2) "0 " 215string(2) " 0" 216string(2) " 2170" 218string(4) " 0" 219string(30) " 0" 220string(4) "0-7]" 221string(1) "o" 222 223-- Iteration 12 -- 224string(1) "0" 225string(1) "o" 226string(1) "0" 227string(1) "o" 228string(2) " 0" 229string(2) "0 " 230string(2) " 0" 231string(2) " 2320" 233string(4) " 0" 234string(30) " 0" 235string(4) "0-7]" 236string(1) "o" 237 238-- Iteration 13 -- 239string(1) "0" 240string(1) "o" 241string(1) "0" 242string(1) "o" 243string(2) " 0" 244string(2) "0 " 245string(2) " 0" 246string(2) " 2470" 248string(4) " 0" 249string(30) " 0" 250string(4) "0-7]" 251string(1) "o" 252 253-- Iteration 14 -- 254string(1) "0" 255string(1) "o" 256string(1) "0" 257string(1) "o" 258string(2) " 0" 259string(2) "0 " 260string(2) " 0" 261string(2) " 2620" 263string(4) " 0" 264string(30) " 0" 265string(4) "0-7]" 266string(1) "o" 267 268-- Iteration 15 -- 269string(1) "0" 270string(1) "o" 271string(1) "0" 272string(1) "o" 273string(2) " 0" 274string(2) "0 " 275string(2) " 0" 276string(2) " 2770" 278string(4) " 0" 279string(30) " 0" 280string(4) "0-7]" 281string(1) "o" 282 283-- Iteration 16 -- 284string(1) "0" 285string(1) "o" 286string(1) "0" 287string(1) "o" 288string(2) " 0" 289string(2) "0 " 290string(2) " 0" 291string(2) " 2920" 293string(4) " 0" 294string(30) " 0" 295string(4) "0-7]" 296string(1) "o" 297 298-- Iteration 17 -- 299string(1) "0" 300string(1) "o" 301string(1) "0" 302string(1) "o" 303string(2) " 0" 304string(2) "0 " 305string(2) " 0" 306string(2) " 3070" 308string(4) " 0" 309string(30) " 0" 310string(4) "0-7]" 311string(1) "o" 312 313-- Iteration 18 -- 314string(1) "0" 315string(1) "o" 316string(1) "0" 317string(1) "o" 318string(2) " 0" 319string(2) "0 " 320string(2) " 0" 321string(2) " 3220" 323string(4) " 0" 324string(30) " 0" 325string(4) "0-7]" 326string(1) "o" 327 328-- Iteration 19 -- 329string(1) "0" 330string(1) "o" 331string(1) "0" 332string(1) "o" 333string(2) " 0" 334string(2) "0 " 335string(2) " 0" 336string(2) " 3370" 338string(4) " 0" 339string(30) " 0" 340string(4) "0-7]" 341string(1) "o" 342Done 343