1--TEST-- 2Test fscanf() function: usage variations - scientific formats with integer values 3--FILE-- 4<?php 5 6/* Test fscanf() to scan different integer values using different scientific format types */ 7 8$file_path = __DIR__; 9 10echo "*** Test fscanf(): different scientific format types with different integer values ***\n"; 11 12// create a file 13$filename = "$file_path/fscanf_variation45.tmp"; 14$file_handle = fopen($filename, "w"); 15if($file_handle == false) 16 exit("Error:failed to open file $filename"); 17 18// different valid integer values 19$valid_ints = 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// various scientific formats 40$scientific_formats = array( "%e", "%he", "%le", "%Le", " %e", "%e ", "% e", "\t%e", "\n%e", "%4e", "%30e", "%[0-1]", "%*e"); 41 42$counter = 1; 43 44// writing to the file 45foreach($valid_ints as $int_value) { 46 @fprintf($file_handle, $int_value); 47 @fprintf($file_handle, "\n"); 48} 49// closing the file 50fclose($file_handle); 51 52// opening the file for reading 53$file_handle = fopen($filename, "r"); 54if($file_handle == false) { 55 exit("Error:failed to open file $filename"); 56} 57 58$counter = 1; 59// reading the values from file using different scientific formats 60foreach($scientific_formats as $scientific_format) { 61 // rewind the file so that for every foreach iteration the file pointer starts from bof 62 rewind($file_handle); 63 echo "\n-- iteration $counter --\n"; 64 while( !feof($file_handle) ) { 65 try { 66 var_dump(fscanf($file_handle,$scientific_format)); 67 } catch (ValueError $exception) { 68 echo $exception->getMessage() . "\n"; 69 } 70 } 71 $counter++; 72} 73 74echo "\n*** Done ***"; 75?> 76--CLEAN-- 77<?php 78$file_path = __DIR__; 79$filename = "$file_path/fscanf_variation45.tmp"; 80unlink($filename); 81?> 82--EXPECT-- 83*** Test fscanf(): different scientific format types with different integer values *** 84 85-- iteration 1 -- 86array(1) { 87 [0]=> 88 float(0) 89} 90array(1) { 91 [0]=> 92 float(1) 93} 94array(1) { 95 [0]=> 96 float(-1) 97} 98array(1) { 99 [0]=> 100 float(-2147483648) 101} 102array(1) { 103 [0]=> 104 float(-2147483647) 105} 106array(1) { 107 [0]=> 108 float(2147483647) 109} 110array(1) { 111 [0]=> 112 float(2147483640) 113} 114array(1) { 115 [0]=> 116 float(4667) 117} 118array(1) { 119 [0]=> 120 float(4779) 121} 122array(1) { 123 [0]=> 124 float(4095) 125} 126array(1) { 127 [0]=> 128 float(250) 129} 130array(1) { 131 [0]=> 132 float(-2147483648) 133} 134array(1) { 135 [0]=> 136 float(2147483647) 137} 138array(1) { 139 [0]=> 140 float(2147483647) 141} 142array(1) { 143 [0]=> 144 float(83) 145} 146array(1) { 147 [0]=> 148 float(1) 149} 150array(1) { 151 [0]=> 152 float(-2147483648) 153} 154array(1) { 155 [0]=> 156 float(2147483647) 157} 158bool(false) 159 160-- iteration 2 -- 161array(1) { 162 [0]=> 163 float(0) 164} 165array(1) { 166 [0]=> 167 float(1) 168} 169array(1) { 170 [0]=> 171 float(-1) 172} 173array(1) { 174 [0]=> 175 float(-2147483648) 176} 177array(1) { 178 [0]=> 179 float(-2147483647) 180} 181array(1) { 182 [0]=> 183 float(2147483647) 184} 185array(1) { 186 [0]=> 187 float(2147483640) 188} 189array(1) { 190 [0]=> 191 float(4667) 192} 193array(1) { 194 [0]=> 195 float(4779) 196} 197array(1) { 198 [0]=> 199 float(4095) 200} 201array(1) { 202 [0]=> 203 float(250) 204} 205array(1) { 206 [0]=> 207 float(-2147483648) 208} 209array(1) { 210 [0]=> 211 float(2147483647) 212} 213array(1) { 214 [0]=> 215 float(2147483647) 216} 217array(1) { 218 [0]=> 219 float(83) 220} 221array(1) { 222 [0]=> 223 float(1) 224} 225array(1) { 226 [0]=> 227 float(-2147483648) 228} 229array(1) { 230 [0]=> 231 float(2147483647) 232} 233bool(false) 234 235-- iteration 3 -- 236array(1) { 237 [0]=> 238 float(0) 239} 240array(1) { 241 [0]=> 242 float(1) 243} 244array(1) { 245 [0]=> 246 float(-1) 247} 248array(1) { 249 [0]=> 250 float(-2147483648) 251} 252array(1) { 253 [0]=> 254 float(-2147483647) 255} 256array(1) { 257 [0]=> 258 float(2147483647) 259} 260array(1) { 261 [0]=> 262 float(2147483640) 263} 264array(1) { 265 [0]=> 266 float(4667) 267} 268array(1) { 269 [0]=> 270 float(4779) 271} 272array(1) { 273 [0]=> 274 float(4095) 275} 276array(1) { 277 [0]=> 278 float(250) 279} 280array(1) { 281 [0]=> 282 float(-2147483648) 283} 284array(1) { 285 [0]=> 286 float(2147483647) 287} 288array(1) { 289 [0]=> 290 float(2147483647) 291} 292array(1) { 293 [0]=> 294 float(83) 295} 296array(1) { 297 [0]=> 298 float(1) 299} 300array(1) { 301 [0]=> 302 float(-2147483648) 303} 304array(1) { 305 [0]=> 306 float(2147483647) 307} 308bool(false) 309 310-- iteration 4 -- 311array(1) { 312 [0]=> 313 float(0) 314} 315array(1) { 316 [0]=> 317 float(1) 318} 319array(1) { 320 [0]=> 321 float(-1) 322} 323array(1) { 324 [0]=> 325 float(-2147483648) 326} 327array(1) { 328 [0]=> 329 float(-2147483647) 330} 331array(1) { 332 [0]=> 333 float(2147483647) 334} 335array(1) { 336 [0]=> 337 float(2147483640) 338} 339array(1) { 340 [0]=> 341 float(4667) 342} 343array(1) { 344 [0]=> 345 float(4779) 346} 347array(1) { 348 [0]=> 349 float(4095) 350} 351array(1) { 352 [0]=> 353 float(250) 354} 355array(1) { 356 [0]=> 357 float(-2147483648) 358} 359array(1) { 360 [0]=> 361 float(2147483647) 362} 363array(1) { 364 [0]=> 365 float(2147483647) 366} 367array(1) { 368 [0]=> 369 float(83) 370} 371array(1) { 372 [0]=> 373 float(1) 374} 375array(1) { 376 [0]=> 377 float(-2147483648) 378} 379array(1) { 380 [0]=> 381 float(2147483647) 382} 383bool(false) 384 385-- iteration 5 -- 386array(1) { 387 [0]=> 388 float(0) 389} 390array(1) { 391 [0]=> 392 float(1) 393} 394array(1) { 395 [0]=> 396 float(-1) 397} 398array(1) { 399 [0]=> 400 float(-2147483648) 401} 402array(1) { 403 [0]=> 404 float(-2147483647) 405} 406array(1) { 407 [0]=> 408 float(2147483647) 409} 410array(1) { 411 [0]=> 412 float(2147483640) 413} 414array(1) { 415 [0]=> 416 float(4667) 417} 418array(1) { 419 [0]=> 420 float(4779) 421} 422array(1) { 423 [0]=> 424 float(4095) 425} 426array(1) { 427 [0]=> 428 float(250) 429} 430array(1) { 431 [0]=> 432 float(-2147483648) 433} 434array(1) { 435 [0]=> 436 float(2147483647) 437} 438array(1) { 439 [0]=> 440 float(2147483647) 441} 442array(1) { 443 [0]=> 444 float(83) 445} 446array(1) { 447 [0]=> 448 float(1) 449} 450array(1) { 451 [0]=> 452 float(-2147483648) 453} 454array(1) { 455 [0]=> 456 float(2147483647) 457} 458bool(false) 459 460-- iteration 6 -- 461array(1) { 462 [0]=> 463 float(0) 464} 465array(1) { 466 [0]=> 467 float(1) 468} 469array(1) { 470 [0]=> 471 float(-1) 472} 473array(1) { 474 [0]=> 475 float(-2147483648) 476} 477array(1) { 478 [0]=> 479 float(-2147483647) 480} 481array(1) { 482 [0]=> 483 float(2147483647) 484} 485array(1) { 486 [0]=> 487 float(2147483640) 488} 489array(1) { 490 [0]=> 491 float(4667) 492} 493array(1) { 494 [0]=> 495 float(4779) 496} 497array(1) { 498 [0]=> 499 float(4095) 500} 501array(1) { 502 [0]=> 503 float(250) 504} 505array(1) { 506 [0]=> 507 float(-2147483648) 508} 509array(1) { 510 [0]=> 511 float(2147483647) 512} 513array(1) { 514 [0]=> 515 float(2147483647) 516} 517array(1) { 518 [0]=> 519 float(83) 520} 521array(1) { 522 [0]=> 523 float(1) 524} 525array(1) { 526 [0]=> 527 float(-2147483648) 528} 529array(1) { 530 [0]=> 531 float(2147483647) 532} 533bool(false) 534 535-- iteration 7 -- 536Bad scan conversion character " " 537Bad scan conversion character " " 538Bad scan conversion character " " 539Bad scan conversion character " " 540Bad scan conversion character " " 541Bad scan conversion character " " 542Bad scan conversion character " " 543Bad scan conversion character " " 544Bad scan conversion character " " 545Bad scan conversion character " " 546Bad scan conversion character " " 547Bad scan conversion character " " 548Bad scan conversion character " " 549Bad scan conversion character " " 550Bad scan conversion character " " 551Bad scan conversion character " " 552Bad scan conversion character " " 553Bad scan conversion character " " 554bool(false) 555 556-- iteration 8 -- 557array(1) { 558 [0]=> 559 float(0) 560} 561array(1) { 562 [0]=> 563 float(1) 564} 565array(1) { 566 [0]=> 567 float(-1) 568} 569array(1) { 570 [0]=> 571 float(-2147483648) 572} 573array(1) { 574 [0]=> 575 float(-2147483647) 576} 577array(1) { 578 [0]=> 579 float(2147483647) 580} 581array(1) { 582 [0]=> 583 float(2147483640) 584} 585array(1) { 586 [0]=> 587 float(4667) 588} 589array(1) { 590 [0]=> 591 float(4779) 592} 593array(1) { 594 [0]=> 595 float(4095) 596} 597array(1) { 598 [0]=> 599 float(250) 600} 601array(1) { 602 [0]=> 603 float(-2147483648) 604} 605array(1) { 606 [0]=> 607 float(2147483647) 608} 609array(1) { 610 [0]=> 611 float(2147483647) 612} 613array(1) { 614 [0]=> 615 float(83) 616} 617array(1) { 618 [0]=> 619 float(1) 620} 621array(1) { 622 [0]=> 623 float(-2147483648) 624} 625array(1) { 626 [0]=> 627 float(2147483647) 628} 629bool(false) 630 631-- iteration 9 -- 632array(1) { 633 [0]=> 634 float(0) 635} 636array(1) { 637 [0]=> 638 float(1) 639} 640array(1) { 641 [0]=> 642 float(-1) 643} 644array(1) { 645 [0]=> 646 float(-2147483648) 647} 648array(1) { 649 [0]=> 650 float(-2147483647) 651} 652array(1) { 653 [0]=> 654 float(2147483647) 655} 656array(1) { 657 [0]=> 658 float(2147483640) 659} 660array(1) { 661 [0]=> 662 float(4667) 663} 664array(1) { 665 [0]=> 666 float(4779) 667} 668array(1) { 669 [0]=> 670 float(4095) 671} 672array(1) { 673 [0]=> 674 float(250) 675} 676array(1) { 677 [0]=> 678 float(-2147483648) 679} 680array(1) { 681 [0]=> 682 float(2147483647) 683} 684array(1) { 685 [0]=> 686 float(2147483647) 687} 688array(1) { 689 [0]=> 690 float(83) 691} 692array(1) { 693 [0]=> 694 float(1) 695} 696array(1) { 697 [0]=> 698 float(-2147483648) 699} 700array(1) { 701 [0]=> 702 float(2147483647) 703} 704bool(false) 705 706-- iteration 10 -- 707array(1) { 708 [0]=> 709 float(0) 710} 711array(1) { 712 [0]=> 713 float(1) 714} 715array(1) { 716 [0]=> 717 float(-1) 718} 719array(1) { 720 [0]=> 721 float(-214) 722} 723array(1) { 724 [0]=> 725 float(-214) 726} 727array(1) { 728 [0]=> 729 float(2147) 730} 731array(1) { 732 [0]=> 733 float(2147) 734} 735array(1) { 736 [0]=> 737 float(4667) 738} 739array(1) { 740 [0]=> 741 float(4779) 742} 743array(1) { 744 [0]=> 745 float(4095) 746} 747array(1) { 748 [0]=> 749 float(250) 750} 751array(1) { 752 [0]=> 753 float(-214) 754} 755array(1) { 756 [0]=> 757 float(2147) 758} 759array(1) { 760 [0]=> 761 float(2147) 762} 763array(1) { 764 [0]=> 765 float(83) 766} 767array(1) { 768 [0]=> 769 float(1) 770} 771array(1) { 772 [0]=> 773 float(-214) 774} 775array(1) { 776 [0]=> 777 float(2147) 778} 779bool(false) 780 781-- iteration 11 -- 782array(1) { 783 [0]=> 784 float(0) 785} 786array(1) { 787 [0]=> 788 float(1) 789} 790array(1) { 791 [0]=> 792 float(-1) 793} 794array(1) { 795 [0]=> 796 float(-2147483648) 797} 798array(1) { 799 [0]=> 800 float(-2147483647) 801} 802array(1) { 803 [0]=> 804 float(2147483647) 805} 806array(1) { 807 [0]=> 808 float(2147483640) 809} 810array(1) { 811 [0]=> 812 float(4667) 813} 814array(1) { 815 [0]=> 816 float(4779) 817} 818array(1) { 819 [0]=> 820 float(4095) 821} 822array(1) { 823 [0]=> 824 float(250) 825} 826array(1) { 827 [0]=> 828 float(-2147483648) 829} 830array(1) { 831 [0]=> 832 float(2147483647) 833} 834array(1) { 835 [0]=> 836 float(2147483647) 837} 838array(1) { 839 [0]=> 840 float(83) 841} 842array(1) { 843 [0]=> 844 float(1) 845} 846array(1) { 847 [0]=> 848 float(-2147483648) 849} 850array(1) { 851 [0]=> 852 float(2147483647) 853} 854bool(false) 855 856-- iteration 12 -- 857array(1) { 858 [0]=> 859 string(1) "0" 860} 861array(1) { 862 [0]=> 863 string(1) "1" 864} 865array(1) { 866 [0]=> 867 NULL 868} 869array(1) { 870 [0]=> 871 NULL 872} 873array(1) { 874 [0]=> 875 NULL 876} 877array(1) { 878 [0]=> 879 NULL 880} 881array(1) { 882 [0]=> 883 NULL 884} 885array(1) { 886 [0]=> 887 NULL 888} 889array(1) { 890 [0]=> 891 NULL 892} 893array(1) { 894 [0]=> 895 NULL 896} 897array(1) { 898 [0]=> 899 NULL 900} 901array(1) { 902 [0]=> 903 NULL 904} 905array(1) { 906 [0]=> 907 NULL 908} 909array(1) { 910 [0]=> 911 NULL 912} 913array(1) { 914 [0]=> 915 NULL 916} 917array(1) { 918 [0]=> 919 string(1) "1" 920} 921array(1) { 922 [0]=> 923 NULL 924} 925array(1) { 926 [0]=> 927 NULL 928} 929bool(false) 930 931-- iteration 13 -- 932array(0) { 933} 934array(0) { 935} 936array(0) { 937} 938array(0) { 939} 940array(0) { 941} 942array(0) { 943} 944array(0) { 945} 946array(0) { 947} 948array(0) { 949} 950array(0) { 951} 952array(0) { 953} 954array(0) { 955} 956array(0) { 957} 958array(0) { 959} 960array(0) { 961} 962array(0) { 963} 964array(0) { 965} 966array(0) { 967} 968bool(false) 969 970*** Done *** 971