1--TEST-- 2Test wordwrap() function : usage variations - unexpected values for width argument 3--FILE-- 4<?php 5/* Prototype : string wordwrap ( string $str [, int $width [, string $break [, bool $cut]]] ) 6 * Description: Wraps buffer to selected number of characters using string break char 7 * Source code: ext/standard/string.c 8*/ 9 10/* 11 * test wordwrap by passing different values for width argument 12*/ 13echo "*** Testing wordwrap() : usage variations ***\n"; 14// initialize all required variables 15$str = 'testing wordwrap function'; 16$break = '<br />\n'; 17$cut = true; 18 19// resource var 20$fp = fopen(__FILE__, "r"); 21 22// get an unset variable 23$unset_var = 10; 24unset($unset_var); 25 26 27// array with different values as width 28$values = array ( 29 // zerovalue for width 30 0, 31 32 // -ve value for width 33 -1, 34 -10, 35 36 // array values 37 array(), 38 array(0), 39 array(1), 40 array(1, 2), 41 array('color' => 'red', 'item' => 'pen'), 42 43 // boolean values 44 true, 45 false, 46 TRUE, 47 FALSE, 48 49 // string values 50 "string", 51 'string', 52 53 // objects 54 new stdclass(), 55 56 // Null value 57 NULL, 58 null, 59 60 // empty string 61 "", 62 '', 63 64 // resource variable 65 $fp, 66 67 // undefined variable 68 @$undefined_var, 69 70 // unset variable 71 @$unset_var 72); 73 74 75// loop though each element of the array and check the working of wordwrap() 76// when $width argument is supplied with different values 77echo "\n--- Testing wordwrap() by supplying different values for 'width' argument ---\n"; 78$counter = 1; 79for($index = 0; $index < count($values); $index ++) { 80 echo "-- Iteration $counter --\n"; 81 $width = $values [$index]; 82 83 var_dump( wordwrap($str, $width) ); 84 var_dump( wordwrap($str, $width, $break) ); 85 86 // cut as false 87 $cut = false; 88 var_dump( wordwrap($str, $width, $break, $cut) ); 89 90 // cut as true 91 $cut = true; 92 var_dump( wordwrap($str, $width, $break, $cut) ); 93 94 $counter ++; 95} 96 97// close the resource 98fclose($fp); 99 100echo "Done\n"; 101?> 102--EXPECTF-- 103*** Testing wordwrap() : usage variations *** 104 105--- Testing wordwrap() by supplying different values for 'width' argument --- 106-- Iteration 1 -- 107string(25) "testing 108wordwrap 109function" 110string(39) "testing<br />\nwordwrap<br />\nfunction" 111string(39) "testing<br />\nwordwrap<br />\nfunction" 112 113Warning: wordwrap(): Can't force cut when width is zero in %s on line %d 114bool(false) 115-- Iteration 2 -- 116string(25) "testing 117wordwrap 118function" 119string(39) "testing<br />\nwordwrap<br />\nfunction" 120string(39) "testing<br />\nwordwrap<br />\nfunction" 121string(223) "<br />\nt<br />\ne<br />\ns<br />\nt<br />\ni<br />\nn<br />\ng<br />\n<br />\nw<br />\no<br />\nr<br />\nd<br />\nw<br />\nr<br />\na<br />\np<br />\n<br />\nf<br />\nu<br />\nn<br />\nc<br />\nt<br />\ni<br />\no<br />\nn" 122-- Iteration 3 -- 123string(25) "testing 124wordwrap 125function" 126string(39) "testing<br />\nwordwrap<br />\nfunction" 127string(39) "testing<br />\nwordwrap<br />\nfunction" 128string(223) "<br />\nt<br />\ne<br />\ns<br />\nt<br />\ni<br />\nn<br />\ng<br />\n<br />\nw<br />\no<br />\nr<br />\nd<br />\nw<br />\nr<br />\na<br />\np<br />\n<br />\nf<br />\nu<br />\nn<br />\nc<br />\nt<br />\ni<br />\no<br />\nn" 129-- Iteration 4 -- 130 131Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 132NULL 133 134Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 135NULL 136 137Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 138NULL 139 140Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 141NULL 142-- Iteration 5 -- 143 144Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 145NULL 146 147Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 148NULL 149 150Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 151NULL 152 153Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 154NULL 155-- Iteration 6 -- 156 157Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 158NULL 159 160Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 161NULL 162 163Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 164NULL 165 166Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 167NULL 168-- Iteration 7 -- 169 170Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 171NULL 172 173Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 174NULL 175 176Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 177NULL 178 179Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 180NULL 181-- Iteration 8 -- 182 183Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 184NULL 185 186Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 187NULL 188 189Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 190NULL 191 192Warning: wordwrap() expects parameter 2 to be integer, array given in %s on line %d 193NULL 194-- Iteration 9 -- 195string(25) "testing 196wordwrap 197function" 198string(39) "testing<br />\nwordwrap<br />\nfunction" 199string(39) "testing<br />\nwordwrap<br />\nfunction" 200string(199) "t<br />\ne<br />\ns<br />\nt<br />\ni<br />\nn<br />\ng<br />\nw<br />\no<br />\nr<br />\nd<br />\nw<br />\nr<br />\na<br />\np<br />\nf<br />\nu<br />\nn<br />\nc<br />\nt<br />\ni<br />\no<br />\nn" 201-- Iteration 10 -- 202string(25) "testing 203wordwrap 204function" 205string(39) "testing<br />\nwordwrap<br />\nfunction" 206string(39) "testing<br />\nwordwrap<br />\nfunction" 207 208Warning: wordwrap(): Can't force cut when width is zero in %s on line %d 209bool(false) 210-- Iteration 11 -- 211string(25) "testing 212wordwrap 213function" 214string(39) "testing<br />\nwordwrap<br />\nfunction" 215string(39) "testing<br />\nwordwrap<br />\nfunction" 216string(199) "t<br />\ne<br />\ns<br />\nt<br />\ni<br />\nn<br />\ng<br />\nw<br />\no<br />\nr<br />\nd<br />\nw<br />\nr<br />\na<br />\np<br />\nf<br />\nu<br />\nn<br />\nc<br />\nt<br />\ni<br />\no<br />\nn" 217-- Iteration 12 -- 218string(25) "testing 219wordwrap 220function" 221string(39) "testing<br />\nwordwrap<br />\nfunction" 222string(39) "testing<br />\nwordwrap<br />\nfunction" 223 224Warning: wordwrap(): Can't force cut when width is zero in %s on line %d 225bool(false) 226-- Iteration 13 -- 227 228Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 229NULL 230 231Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 232NULL 233 234Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 235NULL 236 237Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 238NULL 239-- Iteration 14 -- 240 241Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 242NULL 243 244Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 245NULL 246 247Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 248NULL 249 250Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 251NULL 252-- Iteration 15 -- 253 254Warning: wordwrap() expects parameter 2 to be integer, object given in %s on line %d 255NULL 256 257Warning: wordwrap() expects parameter 2 to be integer, object given in %s on line %d 258NULL 259 260Warning: wordwrap() expects parameter 2 to be integer, object given in %s on line %d 261NULL 262 263Warning: wordwrap() expects parameter 2 to be integer, object given in %s on line %d 264NULL 265-- Iteration 16 -- 266string(25) "testing 267wordwrap 268function" 269string(39) "testing<br />\nwordwrap<br />\nfunction" 270string(39) "testing<br />\nwordwrap<br />\nfunction" 271 272Warning: wordwrap(): Can't force cut when width is zero in %s on line %d 273bool(false) 274-- Iteration 17 -- 275string(25) "testing 276wordwrap 277function" 278string(39) "testing<br />\nwordwrap<br />\nfunction" 279string(39) "testing<br />\nwordwrap<br />\nfunction" 280 281Warning: wordwrap(): Can't force cut when width is zero in %s on line %d 282bool(false) 283-- Iteration 18 -- 284 285Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 286NULL 287 288Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 289NULL 290 291Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 292NULL 293 294Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 295NULL 296-- Iteration 19 -- 297 298Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 299NULL 300 301Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 302NULL 303 304Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 305NULL 306 307Warning: wordwrap() expects parameter 2 to be integer, string given in %s on line %d 308NULL 309-- Iteration 20 -- 310 311Warning: wordwrap() expects parameter 2 to be integer, resource given in %s on line %d 312NULL 313 314Warning: wordwrap() expects parameter 2 to be integer, resource given in %s on line %d 315NULL 316 317Warning: wordwrap() expects parameter 2 to be integer, resource given in %s on line %d 318NULL 319 320Warning: wordwrap() expects parameter 2 to be integer, resource given in %s on line %d 321NULL 322-- Iteration 21 -- 323string(25) "testing 324wordwrap 325function" 326string(39) "testing<br />\nwordwrap<br />\nfunction" 327string(39) "testing<br />\nwordwrap<br />\nfunction" 328 329Warning: wordwrap(): Can't force cut when width is zero in %s on line %d 330bool(false) 331-- Iteration 22 -- 332string(25) "testing 333wordwrap 334function" 335string(39) "testing<br />\nwordwrap<br />\nfunction" 336string(39) "testing<br />\nwordwrap<br />\nfunction" 337 338Warning: wordwrap(): Can't force cut when width is zero in %s on line %d 339bool(false) 340Done 341