1--TEST-- 2Test sprintf() function : usage variations - int formats with int values 3--FILE-- 4<?php 5echo "*** Testing sprintf() : integer formats with integer values ***\n"; 6 7// different valid integer values 8$valid_ints = array( 9 0, 10 1, 11 -1, 12 -2147483648, // max negative integer value 13 -2147483647, 14 2147483647, // max positive integer value 15 2147483640, 16 0x123B, // integer as hexadecimal 17 0x12ab, 18 0Xfff, 19 0XFA, 20 -0x80000000, // max negative integer as hexadecimal 21 0x7fffffff, // max positive integer as hexadecimal 22 0x7FFFFFFF, // max positive integer as hexadecimal 23 0123, // integer as octal 24 01, // should be quivalent to octal 1 25 -020000000000, // max negative integer as octal 26 017777777777 // max positive integer as octal 27); 28// various integer formats 29$int_formats = array( 30 "%d", "%ld", " %d", "%d ", 31 "\t%d", "\n%d", "%4d", "%30d", 32); 33 34$count = 1; 35foreach($valid_ints as $int_value) { 36 echo "\n-- Iteration $count --\n"; 37 38 foreach($int_formats as $format) { 39 var_dump( sprintf($format, $int_value) ); 40 } 41 $count++; 42}; 43 44echo "Done"; 45?> 46--EXPECT-- 47*** Testing sprintf() : integer formats with integer values *** 48 49-- Iteration 1 -- 50string(1) "0" 51string(1) "0" 52string(2) " 0" 53string(2) "0 " 54string(2) " 0" 55string(2) " 560" 57string(4) " 0" 58string(30) " 0" 59 60-- Iteration 2 -- 61string(1) "1" 62string(1) "1" 63string(2) " 1" 64string(2) "1 " 65string(2) " 1" 66string(2) " 671" 68string(4) " 1" 69string(30) " 1" 70 71-- Iteration 3 -- 72string(2) "-1" 73string(2) "-1" 74string(3) " -1" 75string(3) "-1 " 76string(3) " -1" 77string(3) " 78-1" 79string(4) " -1" 80string(30) " -1" 81 82-- Iteration 4 -- 83string(11) "-2147483648" 84string(11) "-2147483648" 85string(12) " -2147483648" 86string(12) "-2147483648 " 87string(12) " -2147483648" 88string(12) " 89-2147483648" 90string(11) "-2147483648" 91string(30) " -2147483648" 92 93-- Iteration 5 -- 94string(11) "-2147483647" 95string(11) "-2147483647" 96string(12) " -2147483647" 97string(12) "-2147483647 " 98string(12) " -2147483647" 99string(12) " 100-2147483647" 101string(11) "-2147483647" 102string(30) " -2147483647" 103 104-- Iteration 6 -- 105string(10) "2147483647" 106string(10) "2147483647" 107string(11) " 2147483647" 108string(11) "2147483647 " 109string(11) " 2147483647" 110string(11) " 1112147483647" 112string(10) "2147483647" 113string(30) " 2147483647" 114 115-- Iteration 7 -- 116string(10) "2147483640" 117string(10) "2147483640" 118string(11) " 2147483640" 119string(11) "2147483640 " 120string(11) " 2147483640" 121string(11) " 1222147483640" 123string(10) "2147483640" 124string(30) " 2147483640" 125 126-- Iteration 8 -- 127string(4) "4667" 128string(4) "4667" 129string(5) " 4667" 130string(5) "4667 " 131string(5) " 4667" 132string(5) " 1334667" 134string(4) "4667" 135string(30) " 4667" 136 137-- Iteration 9 -- 138string(4) "4779" 139string(4) "4779" 140string(5) " 4779" 141string(5) "4779 " 142string(5) " 4779" 143string(5) " 1444779" 145string(4) "4779" 146string(30) " 4779" 147 148-- Iteration 10 -- 149string(4) "4095" 150string(4) "4095" 151string(5) " 4095" 152string(5) "4095 " 153string(5) " 4095" 154string(5) " 1554095" 156string(4) "4095" 157string(30) " 4095" 158 159-- Iteration 11 -- 160string(3) "250" 161string(3) "250" 162string(4) " 250" 163string(4) "250 " 164string(4) " 250" 165string(4) " 166250" 167string(4) " 250" 168string(30) " 250" 169 170-- Iteration 12 -- 171string(11) "-2147483648" 172string(11) "-2147483648" 173string(12) " -2147483648" 174string(12) "-2147483648 " 175string(12) " -2147483648" 176string(12) " 177-2147483648" 178string(11) "-2147483648" 179string(30) " -2147483648" 180 181-- Iteration 13 -- 182string(10) "2147483647" 183string(10) "2147483647" 184string(11) " 2147483647" 185string(11) "2147483647 " 186string(11) " 2147483647" 187string(11) " 1882147483647" 189string(10) "2147483647" 190string(30) " 2147483647" 191 192-- Iteration 14 -- 193string(10) "2147483647" 194string(10) "2147483647" 195string(11) " 2147483647" 196string(11) "2147483647 " 197string(11) " 2147483647" 198string(11) " 1992147483647" 200string(10) "2147483647" 201string(30) " 2147483647" 202 203-- Iteration 15 -- 204string(2) "83" 205string(2) "83" 206string(3) " 83" 207string(3) "83 " 208string(3) " 83" 209string(3) " 21083" 211string(4) " 83" 212string(30) " 83" 213 214-- Iteration 16 -- 215string(1) "1" 216string(1) "1" 217string(2) " 1" 218string(2) "1 " 219string(2) " 1" 220string(2) " 2211" 222string(4) " 1" 223string(30) " 1" 224 225-- Iteration 17 -- 226string(11) "-2147483648" 227string(11) "-2147483648" 228string(12) " -2147483648" 229string(12) "-2147483648 " 230string(12) " -2147483648" 231string(12) " 232-2147483648" 233string(11) "-2147483648" 234string(30) " -2147483648" 235 236-- Iteration 18 -- 237string(10) "2147483647" 238string(10) "2147483647" 239string(11) " 2147483647" 240string(11) "2147483647 " 241string(11) " 2147483647" 242string(11) " 2432147483647" 244string(10) "2147483647" 245string(30) " 2147483647" 246Done 247