1--TEST-- 2Test sprintf() function : usage variations - hexa formats with integer values 3--SKIPIF-- 4<?php 5if (PHP_INT_SIZE != 4) { 6 die("skip this test is for 32bit platform only"); 7} 8?> 9--FILE-- 10<?php 11/* Prototype : string sprintf(string $format [, mixed $arg1 [, mixed ...]]) 12 * Description: Return a formatted string 13 * Source code: ext/standard/formatted_print.c 14*/ 15 16echo "*** Testing sprintf() : hexa formats with integer values ***\n"; 17 18// array of integer values 19$integer_values = array( 20 0, 21 1, 22 -1, 23 -2147483648, // max negative integer value 24 -2147483647, 25 2147483647, // max positive integer value 26 2147483640, 27 0x123B, // integer as hexadecimal 28 0x12ab, 29 0Xfff, 30 0XFA, 31 -0x80000000, // max negative integer as hexadecimal 32 0x7fffffff, // max positive integer as hexadecimal 33 0x7FFFFFFF, // max positive integer as hexadecimal 34 0123, // integer as octal 35 01, // should be quivalent to octal 1 36 -020000000000, // max negative integer as octal 37 017777777777 // max positive integer as octal 38); 39 40// array of hexa formats 41$hexa_formats = array( 42 "%x", "%xx", "%lx", 43 "%Lx", " %x", "%x ", 44 "\t%x", "\n%x", "%4x", 45 "%30x", "%[0-9A-Fa-f]", "%*x" 46); 47 48$count = 1; 49foreach($integer_values as $integer_value) { 50 echo "\n-- Iteration $count --\n"; 51 52 foreach($hexa_formats as $format) { 53 var_dump( sprintf($format, $integer_value) ); 54 } 55 $count++; 56}; 57 58echo "Done"; 59?> 60--EXPECT-- 61*** Testing sprintf() : hexa formats with integer values *** 62 63-- Iteration 1 -- 64string(1) "0" 65string(2) "0x" 66string(1) "0" 67string(1) "x" 68string(2) " 0" 69string(2) "0 " 70string(2) " 0" 71string(2) " 720" 73string(4) " 0" 74string(30) " 0" 75string(10) "0-9A-Fa-f]" 76string(1) "x" 77 78-- Iteration 2 -- 79string(1) "1" 80string(2) "1x" 81string(1) "1" 82string(1) "x" 83string(2) " 1" 84string(2) "1 " 85string(2) " 1" 86string(2) " 871" 88string(4) " 1" 89string(30) " 1" 90string(10) "0-9A-Fa-f]" 91string(1) "x" 92 93-- Iteration 3 -- 94string(8) "ffffffff" 95string(9) "ffffffffx" 96string(8) "ffffffff" 97string(1) "x" 98string(9) " ffffffff" 99string(9) "ffffffff " 100string(9) " ffffffff" 101string(9) " 102ffffffff" 103string(8) "ffffffff" 104string(30) " ffffffff" 105string(10) "0-9A-Fa-f]" 106string(1) "x" 107 108-- Iteration 4 -- 109string(8) "80000000" 110string(9) "80000000x" 111string(8) "80000000" 112string(1) "x" 113string(9) " 80000000" 114string(9) "80000000 " 115string(9) " 80000000" 116string(9) " 11780000000" 118string(8) "80000000" 119string(30) " 80000000" 120string(10) "0-9A-Fa-f]" 121string(1) "x" 122 123-- Iteration 5 -- 124string(8) "80000001" 125string(9) "80000001x" 126string(8) "80000001" 127string(1) "x" 128string(9) " 80000001" 129string(9) "80000001 " 130string(9) " 80000001" 131string(9) " 13280000001" 133string(8) "80000001" 134string(30) " 80000001" 135string(10) "0-9A-Fa-f]" 136string(1) "x" 137 138-- Iteration 6 -- 139string(8) "7fffffff" 140string(9) "7fffffffx" 141string(8) "7fffffff" 142string(1) "x" 143string(9) " 7fffffff" 144string(9) "7fffffff " 145string(9) " 7fffffff" 146string(9) " 1477fffffff" 148string(8) "7fffffff" 149string(30) " 7fffffff" 150string(10) "0-9A-Fa-f]" 151string(1) "x" 152 153-- Iteration 7 -- 154string(8) "7ffffff8" 155string(9) "7ffffff8x" 156string(8) "7ffffff8" 157string(1) "x" 158string(9) " 7ffffff8" 159string(9) "7ffffff8 " 160string(9) " 7ffffff8" 161string(9) " 1627ffffff8" 163string(8) "7ffffff8" 164string(30) " 7ffffff8" 165string(10) "0-9A-Fa-f]" 166string(1) "x" 167 168-- Iteration 8 -- 169string(4) "123b" 170string(5) "123bx" 171string(4) "123b" 172string(1) "x" 173string(5) " 123b" 174string(5) "123b " 175string(5) " 123b" 176string(5) " 177123b" 178string(4) "123b" 179string(30) " 123b" 180string(10) "0-9A-Fa-f]" 181string(1) "x" 182 183-- Iteration 9 -- 184string(4) "12ab" 185string(5) "12abx" 186string(4) "12ab" 187string(1) "x" 188string(5) " 12ab" 189string(5) "12ab " 190string(5) " 12ab" 191string(5) " 19212ab" 193string(4) "12ab" 194string(30) " 12ab" 195string(10) "0-9A-Fa-f]" 196string(1) "x" 197 198-- Iteration 10 -- 199string(3) "fff" 200string(4) "fffx" 201string(3) "fff" 202string(1) "x" 203string(4) " fff" 204string(4) "fff " 205string(4) " fff" 206string(4) " 207fff" 208string(4) " fff" 209string(30) " fff" 210string(10) "0-9A-Fa-f]" 211string(1) "x" 212 213-- Iteration 11 -- 214string(2) "fa" 215string(3) "fax" 216string(2) "fa" 217string(1) "x" 218string(3) " fa" 219string(3) "fa " 220string(3) " fa" 221string(3) " 222fa" 223string(4) " fa" 224string(30) " fa" 225string(10) "0-9A-Fa-f]" 226string(1) "x" 227 228-- Iteration 12 -- 229string(8) "80000000" 230string(9) "80000000x" 231string(8) "80000000" 232string(1) "x" 233string(9) " 80000000" 234string(9) "80000000 " 235string(9) " 80000000" 236string(9) " 23780000000" 238string(8) "80000000" 239string(30) " 80000000" 240string(10) "0-9A-Fa-f]" 241string(1) "x" 242 243-- Iteration 13 -- 244string(8) "7fffffff" 245string(9) "7fffffffx" 246string(8) "7fffffff" 247string(1) "x" 248string(9) " 7fffffff" 249string(9) "7fffffff " 250string(9) " 7fffffff" 251string(9) " 2527fffffff" 253string(8) "7fffffff" 254string(30) " 7fffffff" 255string(10) "0-9A-Fa-f]" 256string(1) "x" 257 258-- Iteration 14 -- 259string(8) "7fffffff" 260string(9) "7fffffffx" 261string(8) "7fffffff" 262string(1) "x" 263string(9) " 7fffffff" 264string(9) "7fffffff " 265string(9) " 7fffffff" 266string(9) " 2677fffffff" 268string(8) "7fffffff" 269string(30) " 7fffffff" 270string(10) "0-9A-Fa-f]" 271string(1) "x" 272 273-- Iteration 15 -- 274string(2) "53" 275string(3) "53x" 276string(2) "53" 277string(1) "x" 278string(3) " 53" 279string(3) "53 " 280string(3) " 53" 281string(3) " 28253" 283string(4) " 53" 284string(30) " 53" 285string(10) "0-9A-Fa-f]" 286string(1) "x" 287 288-- Iteration 16 -- 289string(1) "1" 290string(2) "1x" 291string(1) "1" 292string(1) "x" 293string(2) " 1" 294string(2) "1 " 295string(2) " 1" 296string(2) " 2971" 298string(4) " 1" 299string(30) " 1" 300string(10) "0-9A-Fa-f]" 301string(1) "x" 302 303-- Iteration 17 -- 304string(8) "80000000" 305string(9) "80000000x" 306string(8) "80000000" 307string(1) "x" 308string(9) " 80000000" 309string(9) "80000000 " 310string(9) " 80000000" 311string(9) " 31280000000" 313string(8) "80000000" 314string(30) " 80000000" 315string(10) "0-9A-Fa-f]" 316string(1) "x" 317 318-- Iteration 18 -- 319string(8) "7fffffff" 320string(9) "7fffffffx" 321string(8) "7fffffff" 322string(1) "x" 323string(9) " 7fffffff" 324string(9) "7fffffff " 325string(9) " 7fffffff" 326string(9) " 3277fffffff" 328string(8) "7fffffff" 329string(30) " 7fffffff" 330string(10) "0-9A-Fa-f]" 331string(1) "x" 332Done 333