1--TEST-- 2Test fscanf() function: usage variations - unsigned formats with arrays 3--FILE-- 4<?php 5 6/* Test fscanf() to scan arrays using different unsigned format types */ 7 8$file_path = __DIR__; 9 10echo "*** Test fscanf(): different unsigned format types with arrays ***\n"; 11 12// create a file 13$filename = "$file_path/fscanf_variation42.tmp"; 14$file_handle = fopen($filename, "w"); 15if($file_handle == false) 16 exit("Error:failed to open file $filename"); 17 18// array types 19$array_types = array ( 20 array(), 21 array(0), 22 array(1), 23 array(NULL), 24 array(null), 25 array("string"), 26 array(true), 27 array(TRUE), 28 array(false), 29 array(FALSE), 30 array(1,2,3,4), 31 array(1 => "One", "two" => 2) 32); 33 34$unsigned_formats = array( "%u", "%hu", "%lu", "%Lu", " %u", "%u ", "% u", "\t%u", "\n%u", "%4u", "%30u", "%[0-9]", "%*u"); 35 36$counter = 1; 37 38// writing to the file 39foreach($array_types as $value) { 40 @fprintf($file_handle, "%s", $value); 41 @fprintf($file_handle, "\n"); 42} 43// closing the file 44fclose($file_handle); 45 46// opening the file for reading 47$file_handle = fopen($filename, "r"); 48if($file_handle == false) { 49 exit("Error:failed to open file $filename"); 50} 51 52$counter = 1; 53// reading the values from file using different unsigned formats 54foreach($unsigned_formats as $unsigned_format) { 55 // rewind the file so that for every foreach iteration the file pointer starts from bof 56 rewind($file_handle); 57 echo "\n-- iteration $counter --\n"; 58 while( !feof($file_handle) ) { 59 try { 60 var_dump(fscanf($file_handle,$unsigned_format)); 61 } catch (ValueError $exception) { 62 echo $exception->getMessage() . "\n"; 63 } 64 } 65 $counter++; 66} 67 68echo "\n*** Done ***"; 69?> 70--CLEAN-- 71<?php 72$file_path = __DIR__; 73$filename = "$file_path/fscanf_variation42.tmp"; 74unlink($filename); 75?> 76--EXPECT-- 77*** Test fscanf(): different unsigned format types with arrays *** 78 79-- iteration 1 -- 80array(1) { 81 [0]=> 82 NULL 83} 84array(1) { 85 [0]=> 86 NULL 87} 88array(1) { 89 [0]=> 90 NULL 91} 92array(1) { 93 [0]=> 94 NULL 95} 96array(1) { 97 [0]=> 98 NULL 99} 100array(1) { 101 [0]=> 102 NULL 103} 104array(1) { 105 [0]=> 106 NULL 107} 108array(1) { 109 [0]=> 110 NULL 111} 112array(1) { 113 [0]=> 114 NULL 115} 116array(1) { 117 [0]=> 118 NULL 119} 120array(1) { 121 [0]=> 122 NULL 123} 124array(1) { 125 [0]=> 126 NULL 127} 128bool(false) 129 130-- iteration 2 -- 131array(1) { 132 [0]=> 133 NULL 134} 135array(1) { 136 [0]=> 137 NULL 138} 139array(1) { 140 [0]=> 141 NULL 142} 143array(1) { 144 [0]=> 145 NULL 146} 147array(1) { 148 [0]=> 149 NULL 150} 151array(1) { 152 [0]=> 153 NULL 154} 155array(1) { 156 [0]=> 157 NULL 158} 159array(1) { 160 [0]=> 161 NULL 162} 163array(1) { 164 [0]=> 165 NULL 166} 167array(1) { 168 [0]=> 169 NULL 170} 171array(1) { 172 [0]=> 173 NULL 174} 175array(1) { 176 [0]=> 177 NULL 178} 179bool(false) 180 181-- iteration 3 -- 182array(1) { 183 [0]=> 184 NULL 185} 186array(1) { 187 [0]=> 188 NULL 189} 190array(1) { 191 [0]=> 192 NULL 193} 194array(1) { 195 [0]=> 196 NULL 197} 198array(1) { 199 [0]=> 200 NULL 201} 202array(1) { 203 [0]=> 204 NULL 205} 206array(1) { 207 [0]=> 208 NULL 209} 210array(1) { 211 [0]=> 212 NULL 213} 214array(1) { 215 [0]=> 216 NULL 217} 218array(1) { 219 [0]=> 220 NULL 221} 222array(1) { 223 [0]=> 224 NULL 225} 226array(1) { 227 [0]=> 228 NULL 229} 230bool(false) 231 232-- iteration 4 -- 233array(1) { 234 [0]=> 235 NULL 236} 237array(1) { 238 [0]=> 239 NULL 240} 241array(1) { 242 [0]=> 243 NULL 244} 245array(1) { 246 [0]=> 247 NULL 248} 249array(1) { 250 [0]=> 251 NULL 252} 253array(1) { 254 [0]=> 255 NULL 256} 257array(1) { 258 [0]=> 259 NULL 260} 261array(1) { 262 [0]=> 263 NULL 264} 265array(1) { 266 [0]=> 267 NULL 268} 269array(1) { 270 [0]=> 271 NULL 272} 273array(1) { 274 [0]=> 275 NULL 276} 277array(1) { 278 [0]=> 279 NULL 280} 281bool(false) 282 283-- iteration 5 -- 284array(1) { 285 [0]=> 286 NULL 287} 288array(1) { 289 [0]=> 290 NULL 291} 292array(1) { 293 [0]=> 294 NULL 295} 296array(1) { 297 [0]=> 298 NULL 299} 300array(1) { 301 [0]=> 302 NULL 303} 304array(1) { 305 [0]=> 306 NULL 307} 308array(1) { 309 [0]=> 310 NULL 311} 312array(1) { 313 [0]=> 314 NULL 315} 316array(1) { 317 [0]=> 318 NULL 319} 320array(1) { 321 [0]=> 322 NULL 323} 324array(1) { 325 [0]=> 326 NULL 327} 328array(1) { 329 [0]=> 330 NULL 331} 332bool(false) 333 334-- iteration 6 -- 335array(1) { 336 [0]=> 337 NULL 338} 339array(1) { 340 [0]=> 341 NULL 342} 343array(1) { 344 [0]=> 345 NULL 346} 347array(1) { 348 [0]=> 349 NULL 350} 351array(1) { 352 [0]=> 353 NULL 354} 355array(1) { 356 [0]=> 357 NULL 358} 359array(1) { 360 [0]=> 361 NULL 362} 363array(1) { 364 [0]=> 365 NULL 366} 367array(1) { 368 [0]=> 369 NULL 370} 371array(1) { 372 [0]=> 373 NULL 374} 375array(1) { 376 [0]=> 377 NULL 378} 379array(1) { 380 [0]=> 381 NULL 382} 383bool(false) 384 385-- iteration 7 -- 386Bad scan conversion character " " 387Bad scan conversion character " " 388Bad scan conversion character " " 389Bad scan conversion character " " 390Bad scan conversion character " " 391Bad scan conversion character " " 392Bad scan conversion character " " 393Bad scan conversion character " " 394Bad scan conversion character " " 395Bad scan conversion character " " 396Bad scan conversion character " " 397Bad scan conversion character " " 398bool(false) 399 400-- iteration 8 -- 401array(1) { 402 [0]=> 403 NULL 404} 405array(1) { 406 [0]=> 407 NULL 408} 409array(1) { 410 [0]=> 411 NULL 412} 413array(1) { 414 [0]=> 415 NULL 416} 417array(1) { 418 [0]=> 419 NULL 420} 421array(1) { 422 [0]=> 423 NULL 424} 425array(1) { 426 [0]=> 427 NULL 428} 429array(1) { 430 [0]=> 431 NULL 432} 433array(1) { 434 [0]=> 435 NULL 436} 437array(1) { 438 [0]=> 439 NULL 440} 441array(1) { 442 [0]=> 443 NULL 444} 445array(1) { 446 [0]=> 447 NULL 448} 449bool(false) 450 451-- iteration 9 -- 452array(1) { 453 [0]=> 454 NULL 455} 456array(1) { 457 [0]=> 458 NULL 459} 460array(1) { 461 [0]=> 462 NULL 463} 464array(1) { 465 [0]=> 466 NULL 467} 468array(1) { 469 [0]=> 470 NULL 471} 472array(1) { 473 [0]=> 474 NULL 475} 476array(1) { 477 [0]=> 478 NULL 479} 480array(1) { 481 [0]=> 482 NULL 483} 484array(1) { 485 [0]=> 486 NULL 487} 488array(1) { 489 [0]=> 490 NULL 491} 492array(1) { 493 [0]=> 494 NULL 495} 496array(1) { 497 [0]=> 498 NULL 499} 500bool(false) 501 502-- iteration 10 -- 503array(1) { 504 [0]=> 505 NULL 506} 507array(1) { 508 [0]=> 509 NULL 510} 511array(1) { 512 [0]=> 513 NULL 514} 515array(1) { 516 [0]=> 517 NULL 518} 519array(1) { 520 [0]=> 521 NULL 522} 523array(1) { 524 [0]=> 525 NULL 526} 527array(1) { 528 [0]=> 529 NULL 530} 531array(1) { 532 [0]=> 533 NULL 534} 535array(1) { 536 [0]=> 537 NULL 538} 539array(1) { 540 [0]=> 541 NULL 542} 543array(1) { 544 [0]=> 545 NULL 546} 547array(1) { 548 [0]=> 549 NULL 550} 551bool(false) 552 553-- iteration 11 -- 554array(1) { 555 [0]=> 556 NULL 557} 558array(1) { 559 [0]=> 560 NULL 561} 562array(1) { 563 [0]=> 564 NULL 565} 566array(1) { 567 [0]=> 568 NULL 569} 570array(1) { 571 [0]=> 572 NULL 573} 574array(1) { 575 [0]=> 576 NULL 577} 578array(1) { 579 [0]=> 580 NULL 581} 582array(1) { 583 [0]=> 584 NULL 585} 586array(1) { 587 [0]=> 588 NULL 589} 590array(1) { 591 [0]=> 592 NULL 593} 594array(1) { 595 [0]=> 596 NULL 597} 598array(1) { 599 [0]=> 600 NULL 601} 602bool(false) 603 604-- iteration 12 -- 605array(1) { 606 [0]=> 607 NULL 608} 609array(1) { 610 [0]=> 611 NULL 612} 613array(1) { 614 [0]=> 615 NULL 616} 617array(1) { 618 [0]=> 619 NULL 620} 621array(1) { 622 [0]=> 623 NULL 624} 625array(1) { 626 [0]=> 627 NULL 628} 629array(1) { 630 [0]=> 631 NULL 632} 633array(1) { 634 [0]=> 635 NULL 636} 637array(1) { 638 [0]=> 639 NULL 640} 641array(1) { 642 [0]=> 643 NULL 644} 645array(1) { 646 [0]=> 647 NULL 648} 649array(1) { 650 [0]=> 651 NULL 652} 653bool(false) 654 655-- iteration 13 -- 656array(0) { 657} 658array(0) { 659} 660array(0) { 661} 662array(0) { 663} 664array(0) { 665} 666array(0) { 667} 668array(0) { 669} 670array(0) { 671} 672array(0) { 673} 674array(0) { 675} 676array(0) { 677} 678array(0) { 679} 680bool(false) 681 682*** Done *** 683