1--TEST-- 2Test fscanf() function: usage variations - hexa formats with arrays 3--FILE-- 4<?php 5 6/* Test fscanf() to scan arrays using different hexa format types */ 7 8$file_path = __DIR__; 9 10echo "*** Test fscanf(): different hexa format types with arrays ***\n"; 11 12// create a file 13$filename = "$file_path/fscanf_variation36.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$hexa_formats = array( "%x", "%hx", "%lx", "%Lx", " %x", "%x ", "% x", "\t%x", "\n%x", "%4x", "%30x", "%[0-9]", "%*x"); 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 hexa formats 54foreach($hexa_formats as $hexa_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,$hexa_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_variation36.tmp"; 74unlink($filename); 75?> 76--EXPECT-- 77*** Test fscanf(): different hexa format types with arrays *** 78 79-- iteration 1 -- 80array(1) { 81 [0]=> 82 int(10) 83} 84array(1) { 85 [0]=> 86 int(10) 87} 88array(1) { 89 [0]=> 90 int(10) 91} 92array(1) { 93 [0]=> 94 int(10) 95} 96array(1) { 97 [0]=> 98 int(10) 99} 100array(1) { 101 [0]=> 102 int(10) 103} 104array(1) { 105 [0]=> 106 int(10) 107} 108array(1) { 109 [0]=> 110 int(10) 111} 112array(1) { 113 [0]=> 114 int(10) 115} 116array(1) { 117 [0]=> 118 int(10) 119} 120array(1) { 121 [0]=> 122 int(10) 123} 124array(1) { 125 [0]=> 126 int(10) 127} 128bool(false) 129 130-- iteration 2 -- 131array(1) { 132 [0]=> 133 int(10) 134} 135array(1) { 136 [0]=> 137 int(10) 138} 139array(1) { 140 [0]=> 141 int(10) 142} 143array(1) { 144 [0]=> 145 int(10) 146} 147array(1) { 148 [0]=> 149 int(10) 150} 151array(1) { 152 [0]=> 153 int(10) 154} 155array(1) { 156 [0]=> 157 int(10) 158} 159array(1) { 160 [0]=> 161 int(10) 162} 163array(1) { 164 [0]=> 165 int(10) 166} 167array(1) { 168 [0]=> 169 int(10) 170} 171array(1) { 172 [0]=> 173 int(10) 174} 175array(1) { 176 [0]=> 177 int(10) 178} 179bool(false) 180 181-- iteration 3 -- 182array(1) { 183 [0]=> 184 int(10) 185} 186array(1) { 187 [0]=> 188 int(10) 189} 190array(1) { 191 [0]=> 192 int(10) 193} 194array(1) { 195 [0]=> 196 int(10) 197} 198array(1) { 199 [0]=> 200 int(10) 201} 202array(1) { 203 [0]=> 204 int(10) 205} 206array(1) { 207 [0]=> 208 int(10) 209} 210array(1) { 211 [0]=> 212 int(10) 213} 214array(1) { 215 [0]=> 216 int(10) 217} 218array(1) { 219 [0]=> 220 int(10) 221} 222array(1) { 223 [0]=> 224 int(10) 225} 226array(1) { 227 [0]=> 228 int(10) 229} 230bool(false) 231 232-- iteration 4 -- 233array(1) { 234 [0]=> 235 int(10) 236} 237array(1) { 238 [0]=> 239 int(10) 240} 241array(1) { 242 [0]=> 243 int(10) 244} 245array(1) { 246 [0]=> 247 int(10) 248} 249array(1) { 250 [0]=> 251 int(10) 252} 253array(1) { 254 [0]=> 255 int(10) 256} 257array(1) { 258 [0]=> 259 int(10) 260} 261array(1) { 262 [0]=> 263 int(10) 264} 265array(1) { 266 [0]=> 267 int(10) 268} 269array(1) { 270 [0]=> 271 int(10) 272} 273array(1) { 274 [0]=> 275 int(10) 276} 277array(1) { 278 [0]=> 279 int(10) 280} 281bool(false) 282 283-- iteration 5 -- 284array(1) { 285 [0]=> 286 int(10) 287} 288array(1) { 289 [0]=> 290 int(10) 291} 292array(1) { 293 [0]=> 294 int(10) 295} 296array(1) { 297 [0]=> 298 int(10) 299} 300array(1) { 301 [0]=> 302 int(10) 303} 304array(1) { 305 [0]=> 306 int(10) 307} 308array(1) { 309 [0]=> 310 int(10) 311} 312array(1) { 313 [0]=> 314 int(10) 315} 316array(1) { 317 [0]=> 318 int(10) 319} 320array(1) { 321 [0]=> 322 int(10) 323} 324array(1) { 325 [0]=> 326 int(10) 327} 328array(1) { 329 [0]=> 330 int(10) 331} 332bool(false) 333 334-- iteration 6 -- 335array(1) { 336 [0]=> 337 int(10) 338} 339array(1) { 340 [0]=> 341 int(10) 342} 343array(1) { 344 [0]=> 345 int(10) 346} 347array(1) { 348 [0]=> 349 int(10) 350} 351array(1) { 352 [0]=> 353 int(10) 354} 355array(1) { 356 [0]=> 357 int(10) 358} 359array(1) { 360 [0]=> 361 int(10) 362} 363array(1) { 364 [0]=> 365 int(10) 366} 367array(1) { 368 [0]=> 369 int(10) 370} 371array(1) { 372 [0]=> 373 int(10) 374} 375array(1) { 376 [0]=> 377 int(10) 378} 379array(1) { 380 [0]=> 381 int(10) 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 int(10) 404} 405array(1) { 406 [0]=> 407 int(10) 408} 409array(1) { 410 [0]=> 411 int(10) 412} 413array(1) { 414 [0]=> 415 int(10) 416} 417array(1) { 418 [0]=> 419 int(10) 420} 421array(1) { 422 [0]=> 423 int(10) 424} 425array(1) { 426 [0]=> 427 int(10) 428} 429array(1) { 430 [0]=> 431 int(10) 432} 433array(1) { 434 [0]=> 435 int(10) 436} 437array(1) { 438 [0]=> 439 int(10) 440} 441array(1) { 442 [0]=> 443 int(10) 444} 445array(1) { 446 [0]=> 447 int(10) 448} 449bool(false) 450 451-- iteration 9 -- 452array(1) { 453 [0]=> 454 int(10) 455} 456array(1) { 457 [0]=> 458 int(10) 459} 460array(1) { 461 [0]=> 462 int(10) 463} 464array(1) { 465 [0]=> 466 int(10) 467} 468array(1) { 469 [0]=> 470 int(10) 471} 472array(1) { 473 [0]=> 474 int(10) 475} 476array(1) { 477 [0]=> 478 int(10) 479} 480array(1) { 481 [0]=> 482 int(10) 483} 484array(1) { 485 [0]=> 486 int(10) 487} 488array(1) { 489 [0]=> 490 int(10) 491} 492array(1) { 493 [0]=> 494 int(10) 495} 496array(1) { 497 [0]=> 498 int(10) 499} 500bool(false) 501 502-- iteration 10 -- 503array(1) { 504 [0]=> 505 int(10) 506} 507array(1) { 508 [0]=> 509 int(10) 510} 511array(1) { 512 [0]=> 513 int(10) 514} 515array(1) { 516 [0]=> 517 int(10) 518} 519array(1) { 520 [0]=> 521 int(10) 522} 523array(1) { 524 [0]=> 525 int(10) 526} 527array(1) { 528 [0]=> 529 int(10) 530} 531array(1) { 532 [0]=> 533 int(10) 534} 535array(1) { 536 [0]=> 537 int(10) 538} 539array(1) { 540 [0]=> 541 int(10) 542} 543array(1) { 544 [0]=> 545 int(10) 546} 547array(1) { 548 [0]=> 549 int(10) 550} 551bool(false) 552 553-- iteration 11 -- 554array(1) { 555 [0]=> 556 int(10) 557} 558array(1) { 559 [0]=> 560 int(10) 561} 562array(1) { 563 [0]=> 564 int(10) 565} 566array(1) { 567 [0]=> 568 int(10) 569} 570array(1) { 571 [0]=> 572 int(10) 573} 574array(1) { 575 [0]=> 576 int(10) 577} 578array(1) { 579 [0]=> 580 int(10) 581} 582array(1) { 583 [0]=> 584 int(10) 585} 586array(1) { 587 [0]=> 588 int(10) 589} 590array(1) { 591 [0]=> 592 int(10) 593} 594array(1) { 595 [0]=> 596 int(10) 597} 598array(1) { 599 [0]=> 600 int(10) 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