123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- --TEST--
- SplFileObject::fputcsv(): Usage variations -- with line without any CSV fields
- --FILE--
- <?php
- /* Testing fputcsv() to write to a file when the field has no CSV format */
- echo "*** Testing fputcsv() : with no CSV format in the field ***\n";
- /* the array is with three elements in it. Each element should be read as
- 1st element is delimiter, 2nd element is enclosure
- and 3rd element is csv fields
- */
- $fields = array( array('water_fruit\n'),
- array("water_fruit\n"),
- array("")
- );
- $file_path = __DIR__;
- $file = "$file_path/fputcsv_variation10.tmp";
- $file_modes = array ("r+", "r+b", "r+t",
- "a+", "a+b", "a+t",
- "w+", "w+b", "w+t",
- "x+", "x+b", "x+t");
- $loop_counter = 1;
- foreach ($fields as $field) {
- for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
- echo "\n-- file opened in $file_modes[$mode_counter] --\n";
- // create the file and add the content with has csv fields
- if ( strstr($file_modes[$mode_counter], "r") ) {
- $fo = new SplFileObject($file, 'w');
- } else {
- $fo = new SplFileObject($file, $file_modes[$mode_counter]);
- }
- $csv_field = $field;
- // write to a file in csv format
- var_dump( $fo->fputcsv($csv_field) );
- // check the file pointer position and eof
- var_dump( $fo->ftell() );
- var_dump( $fo->eof() );
- //close the file
- unset($fo);
- // print the file contents
- var_dump( file_get_contents($file) );
- //delete file
- unlink($file);
- } //end of mode loop
- } // end of foreach
- echo "Done\n";
- ?>
- --EXPECTF--
- *** Testing fputcsv() : with no CSV format in the field ***
- -- file opened in r+ --
- int(16)
- int(16)
- bool(false)
- string(16) ""water_fruit\n"
- "
- -- file opened in r+b --
- int(16)
- int(16)
- bool(false)
- string(16) ""water_fruit\n"
- "
- -- file opened in r+t --
- int(16)
- int(16)
- bool(false)
- string(%d) ""water_fruit\n"
- "
- -- file opened in a+ --
- int(16)
- int(16)
- bool(false)
- string(16) ""water_fruit\n"
- "
- -- file opened in a+b --
- int(16)
- int(16)
- bool(false)
- string(16) ""water_fruit\n"
- "
- -- file opened in a+t --
- int(16)
- int(16)
- bool(false)
- string(%d) ""water_fruit\n"
- "
- -- file opened in w+ --
- int(16)
- int(16)
- bool(false)
- string(16) ""water_fruit\n"
- "
- -- file opened in w+b --
- int(16)
- int(16)
- bool(false)
- string(16) ""water_fruit\n"
- "
- -- file opened in w+t --
- int(16)
- int(16)
- bool(false)
- string(%d) ""water_fruit\n"
- "
- -- file opened in x+ --
- int(16)
- int(16)
- bool(false)
- string(16) ""water_fruit\n"
- "
- -- file opened in x+b --
- int(16)
- int(16)
- bool(false)
- string(16) ""water_fruit\n"
- "
- -- file opened in x+t --
- int(16)
- int(16)
- bool(false)
- string(%d) ""water_fruit\n"
- "
- -- file opened in r+ --
- int(15)
- int(15)
- bool(false)
- string(15) ""water_fruit
- "
- "
- -- file opened in r+b --
- int(15)
- int(15)
- bool(false)
- string(15) ""water_fruit
- "
- "
- -- file opened in r+t --
- int(15)
- int(15)
- bool(false)
- string(%d) ""water_fruit
- "
- "
- -- file opened in a+ --
- int(15)
- int(15)
- bool(false)
- string(15) ""water_fruit
- "
- "
- -- file opened in a+b --
- int(15)
- int(15)
- bool(false)
- string(15) ""water_fruit
- "
- "
- -- file opened in a+t --
- int(15)
- int(15)
- bool(false)
- string(%d) ""water_fruit
- "
- "
- -- file opened in w+ --
- int(15)
- int(15)
- bool(false)
- string(15) ""water_fruit
- "
- "
- -- file opened in w+b --
- int(15)
- int(15)
- bool(false)
- string(15) ""water_fruit
- "
- "
- -- file opened in w+t --
- int(15)
- int(15)
- bool(false)
- string(%d) ""water_fruit
- "
- "
- -- file opened in x+ --
- int(15)
- int(15)
- bool(false)
- string(15) ""water_fruit
- "
- "
- -- file opened in x+b --
- int(15)
- int(15)
- bool(false)
- string(15) ""water_fruit
- "
- "
- -- file opened in x+t --
- int(15)
- int(15)
- bool(false)
- string(%d) ""water_fruit
- "
- "
- -- file opened in r+ --
- int(1)
- int(1)
- bool(false)
- string(1) "
- "
- -- file opened in r+b --
- int(1)
- int(1)
- bool(false)
- string(1) "
- "
- -- file opened in r+t --
- int(1)
- int(1)
- bool(false)
- string(%d) "
- "
- -- file opened in a+ --
- int(1)
- int(1)
- bool(false)
- string(1) "
- "
- -- file opened in a+b --
- int(1)
- int(1)
- bool(false)
- string(1) "
- "
- -- file opened in a+t --
- int(1)
- int(1)
- bool(false)
- string(%d) "
- "
- -- file opened in w+ --
- int(1)
- int(1)
- bool(false)
- string(1) "
- "
- -- file opened in w+b --
- int(1)
- int(1)
- bool(false)
- string(1) "
- "
- -- file opened in w+t --
- int(1)
- int(1)
- bool(false)
- string(%d) "
- "
- -- file opened in x+ --
- int(1)
- int(1)
- bool(false)
- string(1) "
- "
- -- file opened in x+b --
- int(1)
- int(1)
- bool(false)
- string(1) "
- "
- -- file opened in x+t --
- int(1)
- int(1)
- bool(false)
- string(%d) "
- "
- Done
|