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