diff options
author | Raghubansh Kumar <kraghuba@php.net> | 2007-08-08 13:13:18 +0000 |
---|---|---|
committer | Raghubansh Kumar <kraghuba@php.net> | 2007-08-08 13:13:18 +0000 |
commit | 9bd00453598ef6baefc191d644ede998d6d8b504 (patch) | |
tree | d802476f99cbd6116f4d3bece2f63ae918cd1b68 /ext/standard/tests | |
parent | af3de070e548e731a441c78306c3c682d9e5bfe2 (diff) | |
download | php-git-9bd00453598ef6baefc191d644ede998d6d8b504.tar.gz |
New Testcases for fgetcsv() function
Diffstat (limited to 'ext/standard/tests')
32 files changed, 27726 insertions, 0 deletions
diff --git a/ext/standard/tests/file/fgetcsv_error.phpt b/ext/standard/tests/file/fgetcsv_error.phpt new file mode 100644 index 0000000000..c3ace9ab87 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_error.phpt @@ -0,0 +1,95 @@ +--TEST-- +Test fgetcsv() function : error conditions +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +echo "*** Testing error conditions ***\n"; +// zero argument +echo "-- Testing fgetcsv() with zero argument --\n"; +var_dump( fgetcsv() ); + +// more than expected no. of args +echo "-- Testing fgetcsv() with more than expected number of arguments --\n"; +$fp = fopen(__FILE__, "r"); +$len = 1024; +$delim = ";"; +$enclosure ="\""; +var_dump( fgetcsv($fp, $len, $delim, $enclosure, $fp) ); +fclose($fp); + +// test invalid arguments : non-resources +echo "-- Testing fgetcsv() with invalid arguments --\n"; +$invalid_args = array ( + "string", + 10, + 10.5, + true, + array(1,2,3), + new stdclass, +); +/* loop to test fgetcsv() with different invalid type of args */ +for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) { + echo "-- Iteration $loop_counter --\n"; + var_dump( fgetcsv($invalid_args[$loop_counter - 1]) ); // with default args + var_dump( fgetcsv($invalid_args[$loop_counter - 1], $len, $delim, $enclosure) ); // all args specified +} + +echo "Done\n"; +--EXPECTF-- +*** Testing error conditions *** +-- Testing fgetcsv() with zero argument -- + +Warning: fgetcsv() expects at least 1 parameter, 0 given in %s on line %d +NULL +-- Testing fgetcsv() with more than expected number of arguments -- + +Warning: fgetcsv() expects at most 4 parameters, 5 given in %s on line %d +NULL +-- Testing fgetcsv() with invalid arguments -- +-- Iteration 1 -- + +Warning: fgetcsv() expects parameter 1 to be resource, string given in %s on line %d +NULL + +Warning: fgetcsv() expects parameter 1 to be resource, string given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: fgetcsv() expects parameter 1 to be resource, integer given in %s on line %d +NULL + +Warning: fgetcsv() expects parameter 1 to be resource, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: fgetcsv() expects parameter 1 to be resource, double given in %s on line %d +NULL + +Warning: fgetcsv() expects parameter 1 to be resource, double given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: fgetcsv() expects parameter 1 to be resource, boolean given in %s on line %d +NULL + +Warning: fgetcsv() expects parameter 1 to be resource, boolean given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: fgetcsv() expects parameter 1 to be resource, array given in %s on line %d +NULL + +Warning: fgetcsv() expects parameter 1 to be resource, array given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: fgetcsv() expects parameter 1 to be resource, object given in %s on line %d +NULL + +Warning: fgetcsv() expects parameter 1 to be resource, object given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/file/fgetcsv_variation1.phpt b/ext/standard/tests/file/fgetcsv_variation1.phpt new file mode 100644 index 0000000000..8a698e40a0 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation1.phpt @@ -0,0 +1,1412 @@ +--TEST-- +Test fgetcsv() : usage variations - with all parameters specified +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() to read a file when all its parameters are provided */ + +echo "*** Testing fgetcsv() : with all parameters specified ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation1.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blank line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use the right delimiter and enclosure with max length + var_dump( fgetcsv($file_handle, 1024, $delimiter, $enclosure) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with all parameters specified *** + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation10.phpt b/ext/standard/tests/file/fgetcsv_variation10.phpt new file mode 100644 index 0000000000..2d00f9993e --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation10.phpt @@ -0,0 +1,1295 @@ +--TEST-- +Test fgetcsv() : usage variations - file pointer pointing to EOF (Bug #42175) +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() by reading from a file when the file pointer is pointing to end of file */ + +echo "*** Testing fgetcsv() : with file pointer pointing to EOF ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation10.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blank line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // set the file pointer to EOF + var_dump( fseek($file_handle, 0, SEEK_END) ); + + // call fgetcsv() to parse csv fields + + // now file pointer should point to end of the file, try reading again + var_dump( feof($file_handle) ); + var_dump( fgetcsv($file_handle, 1024, $delimiter, $enclosure) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + var_dump( fgetcsv($file_handle) ); // with default args + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing fgetcsv() : with file pointer pointing to EOF *** + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(false) +bool(false) +int(55) +bool(true) +bool(false) +int(55) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(false) +bool(false) +int(55) +bool(true) +bool(false) +int(55) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(false) +bool(false) +int(55) +bool(true) +bool(false) +int(55) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(false) +bool(false) +int(55) +bool(true) +bool(false) +int(55) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(false) +bool(false) +int(55) +bool(true) +bool(false) +int(55) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(false) +bool(false) +int(55) +bool(true) +bool(false) +int(55) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(false) +bool(false) +int(55) +bool(true) +bool(false) +int(55) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(false) +bool(false) +int(55) +bool(true) +bool(false) +int(55) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(false) +bool(false) +int(55) +bool(true) +bool(false) +int(55) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(false) +bool(false) +int(55) +bool(true) +bool(false) +int(55) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(false) +bool(false) +int(57) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(false) +bool(false) +int(59) +bool(true) +bool(false) +int(59) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(false) +bool(false) +int(59) +bool(true) +bool(false) +int(59) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(false) +bool(false) +int(59) +bool(true) +bool(false) +int(59) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(false) +bool(false) +int(59) +bool(true) +bool(false) +int(59) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(false) +bool(false) +int(59) +bool(true) +bool(false) +int(59) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(false) +bool(false) +int(59) +bool(true) +bool(false) +int(59) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(false) +bool(false) +int(59) +bool(true) +bool(false) +int(59) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(false) +bool(false) +int(59) +bool(true) +bool(false) +int(59) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(false) +bool(false) +int(59) +bool(true) +bool(false) +int(59) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(false) +bool(false) +int(59) +bool(true) +bool(false) +int(59) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(false) +bool(false) +int(63) +bool(true) +bool(false) +int(63) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(false) +bool(false) +int(63) +bool(true) +bool(false) +int(63) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(false) +bool(false) +int(63) +bool(true) +bool(false) +int(63) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(false) +bool(false) +int(63) +bool(true) +bool(false) +int(63) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(false) +bool(false) +int(63) +bool(true) +bool(false) +int(63) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(false) +bool(false) +int(63) +bool(true) +bool(false) +int(63) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(false) +bool(false) +int(63) +bool(true) +bool(false) +int(63) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(false) +bool(false) +int(63) +bool(true) +bool(false) +int(63) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(false) +bool(false) +int(63) +bool(true) +bool(false) +int(63) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(false) +bool(false) +int(63) +bool(true) +bool(false) +int(63) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(false) +bool(false) +int(65) +bool(true) +bool(false) +int(65) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(false) +bool(false) +int(65) +bool(true) +bool(false) +int(65) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(false) +bool(false) +int(65) +bool(true) +bool(false) +int(65) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(false) +bool(false) +int(65) +bool(true) +bool(false) +int(65) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(false) +bool(false) +int(65) +bool(true) +bool(false) +int(65) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(false) +bool(false) +int(65) +bool(true) +bool(false) +int(65) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(false) +bool(false) +int(65) +bool(true) +bool(false) +int(65) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(false) +bool(false) +int(65) +bool(true) +bool(false) +int(65) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(false) +bool(false) +int(65) +bool(true) +bool(false) +int(65) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(false) +bool(false) +int(65) +bool(true) +bool(false) +int(65) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(false) +bool(false) +int(%d) +bool(true) +bool(false) +int(%d) +bool(true) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation11.phpt b/ext/standard/tests/file/fgetcsv_variation11.phpt new file mode 100644 index 0000000000..815ede6f01 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation11.phpt @@ -0,0 +1,1835 @@ +--TEST-- +Test fgetcsv() : usage variations - with different enclosure but same delimiter +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() by reading from a file when different enclosure that is not + present in the data being read and delimiter which is present in the data */ + +echo "*** Testing fgetcsv() : with different enclosure but same delimiter char ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation11.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blan line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + + // use different delimiter but same enclosure char + fseek($file_handle, 0, SEEK_SET); + $enc = "+"; + var_dump( fgetcsv($file_handle, 1024, $delimiter, $enc) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with different enclosure but same delimiter char *** + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(7) ""fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(7) ""fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(7) ""fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(7) ""fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(7) ""fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(7) ""fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(7) ""fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(7) ""fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(7) ""fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(7) ""fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(7) ""fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(7) ""fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(7) ""fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(7) ""fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(7) ""water"" + [1]=> + string(7) ""fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(7) "^water^" + [1]=> + string(7) "^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(7) "^water^" + [1]=> + string(7) "^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(7) "^water^" + [1]=> + string(7) "^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(7) "^water^" + [1]=> + string(7) "^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(7) "^water^" + [1]=> + string(7) "^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(7) "^water^" + [1]=> + string(7) "^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(7) "^water^" + [1]=> + string(7) "^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(7) "^water^" + [1]=> + string(7) "^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(7) "^water^" + [1]=> + string(7) "^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(7) "^water^" + [1]=> + string(7) "^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(7) "^water^" + [1]=> + string(7) "^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(7) "^water^" + [1]=> + string(7) "^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(7) "^water^" + [1]=> + string(7) "^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(7) "^water^" + [1]=> + string(7) "^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(7) "^water^" + [1]=> + string(7) "^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(7) "&water&" + [1]=> + string(7) "&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(7) "&water&" + [1]=> + string(7) "&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(7) "&water&" + [1]=> + string(7) "&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(7) "&water&" + [1]=> + string(7) "&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(7) "&water&" + [1]=> + string(7) "&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(7) "&water&" + [1]=> + string(7) "&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(7) "&water&" + [1]=> + string(7) "&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(7) "&water&" + [1]=> + string(7) "&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(7) "&water&" + [1]=> + string(7) "&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(7) "&water&" + [1]=> + string(7) "&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(7) "&water&" + [1]=> + string(7) "&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(7) "&water&" + [1]=> + string(7) "&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(7) "&water&" + [1]=> + string(7) "&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(7) "&water&" + [1]=> + string(7) "&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(7) "&water&" + [1]=> + string(7) "&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(5) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(5) "fruit" + [4]=> + string(3) "air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(5) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(5) "fruit" + [4]=> + string(3) "air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(5) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(5) "fruit" + [4]=> + string(3) "air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(5) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(5) "fruit" + [4]=> + string(3) "air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(5) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(5) "fruit" + [4]=> + string(3) "air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(5) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(5) "fruit" + [4]=> + string(3) "air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(5) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(5) "fruit" + [4]=> + string(3) "air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(5) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(5) "fruit" + [4]=> + string(3) "air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(5) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(5) "fruit" + [4]=> + string(3) "air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(5) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(5) "fruit" + [4]=> + string(3) "air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(5) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(5) "fruit" + [4]=> + string(3) "air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(5) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(5) "fruit" + [4]=> + string(3) "air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(5) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(5) "fruit" + [4]=> + string(3) "air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(5) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(5) "fruit" + [4]=> + string(3) "air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(5) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(5) "fruit" + [4]=> + string(3) "air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(9) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(3) "air" + [8]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(9) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(3) "air" + [8]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(9) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(3) "air" + [8]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(9) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(3) "air" + [8]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(9) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(3) "air" + [8]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(9) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(3) "air" + [8]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(9) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(3) "air" + [8]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(9) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(3) "air" + [8]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(9) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(3) "air" + [8]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(9) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(3) "air" + [8]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(9) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(3) "air" + [8]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(9) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(3) "air" + [8]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(9) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(3) "air" + [8]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(9) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(3) "air" + [8]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(9) { + [0]=> + string(0) "" + [1]=> + string(5) "water" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(5) "fruit" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(3) "air" + [8]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(6) { + [0]=> + string(6) "&""""&" + [1]=> + string(3) "&"&" + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(3) "&,&" + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(6) { + [0]=> + string(6) "&""""&" + [1]=> + string(3) "&"&" + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(3) "&,&" + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(6) { + [0]=> + string(6) "&""""&" + [1]=> + string(3) "&"&" + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(3) "&,&" + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(6) { + [0]=> + string(6) "&""""&" + [1]=> + string(3) "&"&" + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(3) "&,&" + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(6) { + [0]=> + string(6) "&""""&" + [1]=> + string(3) "&"&" + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(3) "&,&" + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(6) { + [0]=> + string(6) "&""""&" + [1]=> + string(3) "&"&" + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(3) "&,&" + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(6) { + [0]=> + string(6) "&""""&" + [1]=> + string(3) "&"&" + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(3) "&,&" + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(6) { + [0]=> + string(6) "&""""&" + [1]=> + string(3) "&"&" + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(3) "&,&" + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(6) { + [0]=> + string(6) "&""""&" + [1]=> + string(3) "&"&" + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(3) "&,&" + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(6) { + [0]=> + string(6) "&""""&" + [1]=> + string(3) "&"&" + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(3) "&,&" + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(6) { + [0]=> + string(6) "&""""&" + [1]=> + string(3) "&"&" + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(3) "&,&" + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(6) { + [0]=> + string(6) "&""""&" + [1]=> + string(3) "&"&" + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(3) "&,&" + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(6) { + [0]=> + string(6) "&""""&" + [1]=> + string(3) "&"&" + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(3) "&,&" + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(6) { + [0]=> + string(6) "&""""&" + [1]=> + string(3) "&"&" + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(3) "&,&" + [5]=> + string(4) ",,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(6) { + [0]=> + string(6) "&""""&" + [1]=> + string(3) "&"&" + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(3) "&,&" + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/fgetcsv_variation12.phpt b/ext/standard/tests/file/fgetcsv_variation12.phpt new file mode 100644 index 0000000000..e513fe6761 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation12.phpt @@ -0,0 +1,957 @@ +--TEST-- +Test fgetcsv() : usage variations - two chars as enclosure & delimiter (various read and append modes) +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() by providing two characters for enclosure and delimiter parameters */ + +echo "*** Testing fgetcsv() : with two chars as enclosure & delimiter ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation12.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + fwrite($file_handle, $csv_field . "\n"); + + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blank line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use delimiter & enclosure char of two chars + fseek($file_handle, 0, SEEK_SET); + $del = "++"; + $enc = "%%"; + var_dump( fgetcsv($file_handle, 1024, $del, $enc) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing fgetcsv() : with two chars as enclosure & delimiter *** + +-- Testing fgetcsv() with file opened using r mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation13.phpt b/ext/standard/tests/file/fgetcsv_variation13.phpt new file mode 100644 index 0000000000..a00405b90b --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation13.phpt @@ -0,0 +1,189 @@ +--TEST-- +Test fgetcsv() : usage variations - with line without any csv fields + +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() to read a line from a file which doesn't have any CSV field */ + +echo "*** Testing fgetcsv() : reading the line which is without csv fields ***\n"; + + +$filename = dirname(__FILE__) . '/fgetcsv_variation13.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + // write line of text + fwrite($file_handle, "This is line of text without csv fields\n"); + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + + // read the line which is without csv fields, provide delimiter and see the working of fgetcsv + $fp_pos = ftell($file_handle); + var_dump( fgetcsv($file_handle) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : reading the line which is without csv fields *** + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation14.phpt b/ext/standard/tests/file/fgetcsv_variation14.phpt new file mode 100644 index 0000000000..654d7728cb --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation14.phpt @@ -0,0 +1,189 @@ +--TEST-- +Test fgetcsv() : usage variations - reading the blank line (Bug #42228) +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() by reading a file containing a blank line */ + +echo "*** Testing fgetcsv() : reading the blank line ***\n"; + + +$filename = dirname(__FILE__) . '/fgetcsv_variation14.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + // write a blank line + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // read the next line which is a blank line to see the working of fgetcsv + $fp_pos = ftell($file_handle); + var_dump( fgetcsv($file_handle, 1024) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : reading the blank line *** + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(true) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation15.phpt b/ext/standard/tests/file/fgetcsv_variation15.phpt new file mode 100644 index 0000000000..b36b88ed3f --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation15.phpt @@ -0,0 +1,940 @@ +--TEST-- +Test fgetcsv() : usage variations - with default enclosure +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() to read a file when provided with default enclosure character */ + +echo "*** Testing fgetcsv() : with default enclosure ***\n"; + +/* the array is with two elements in it. Each element should be read as + 1st element is delimiter & 2nd element is csv fields +*/ +$csv_lists = array ( + array(',', 'water,fruit'), + array(' ', 'water fruit'), + array(' ', '"water" "fruit"'), + array('\\', 'water\\"fruit"\\"air"'), + array('\\', '"water"\\"fruit"\\"""'), +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation15.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $csv_field = $csv_list[1]; + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blan line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + var_dump( fgetcsv($file_handle, 1024, $delimiter) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with default enclosure *** + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation16.phpt b/ext/standard/tests/file/fgetcsv_variation16.phpt new file mode 100644 index 0000000000..904c422428 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation16.phpt @@ -0,0 +1,944 @@ +--TEST-- +Test fgetcsv() : usage variations - with default enclosure & length as 0 +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() to read a file when provided with default enclosure character + and length value equal to zero +*/ + +echo "*** Testing fgetcsv() : with default enclosure & length as 0 ***\n"; + +/* the array is with two elements in it. Each element should be read as + 1st element is delimiter & 2nd element is csv fields +*/ +$csv_lists = array ( + array(',', 'water,fruit'), + array(' ', 'water fruit'), + array(' ', '"water" "fruit"'), + array('\\', 'water\\"fruit"\\"air"'), + array('\\', '"water"\\"fruit"\\"""'), +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation16.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $csv_field = $csv_list[1]; + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blan line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use length as 0 + fseek($file_handle, 0, SEEK_SET); + var_dump( fgetcsv($file_handle, 0, $delimiter) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with default enclosure & length as 0 *** + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation17.phpt b/ext/standard/tests/file/fgetcsv_variation17.phpt new file mode 100644 index 0000000000..a54f8da61e --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation17.phpt @@ -0,0 +1,1565 @@ +--TEST-- +Test fgetcsv() : usage variations - with default enclosure & length less than line size +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() to read a file when provided with default enclosure character + and length value less than the size of line being read + */ + +echo "*** Testing fgetcsv() : with default enclosure & length less than line size ***\n"; + +/* the array is with two elements in it. Each element should be read as + 1st element is delimiter & 2nd element is csv fields +*/ +$csv_lists = array ( + array(',', 'water,fruit'), + array(' ', 'water fruit'), + array(' ', '"water" "fruit"'), + array('\\', 'water\\"fruit"\\"air"'), + array('\\', '"water"\\"fruit"\\"""'), +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation17.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $csv_field = $csv_list[1]; + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blan line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use length as less than the actual size of the line + fseek($file_handle, 0, SEEK_SET); + var_dump( fgetcsv($file_handle, 9, $delimiter) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // read rest of the line + var_dump( fgetcsv($file_handle, 1024, $delimiter) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with default enclosure & length less than line size *** + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(3) "fru" +} +int(9) +bool(false) +array(1) { + [0]=> + string(2) "it" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(60) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(60) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(60) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(60) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(60) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(60) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(60) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(60) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(60) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(60) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(60) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(60) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(60) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(60) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(3) "air" +} +int(20) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(60) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(3) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" + [2]=> + string(43) "" +This is line of text without csv fields + +" +} +int(61) +bool(true) +bool(false) +int(61) +bool(true) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation18.phpt b/ext/standard/tests/file/fgetcsv_variation18.phpt new file mode 100644 index 0000000000..19915e816f --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation18.phpt @@ -0,0 +1,690 @@ +--TEST-- +Test fgetcsv() : usage variations - with default enclosure and different delimiter +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() to read a file when provided with default enclosure character + and with delimiter character which is not in the line being read by fgetcsv() +*/ + +echo "*** Testing fgetcsv() : with default enclosure and different delimiter ***\n"; + +/* the array is with two elements in it. Each element should be read as + 1st element is delimiter & 2nd element is csv fields +*/ +$csv_lists = array ( + array(',', 'water,fruit'), + array(' ', 'water fruit'), + array(' ', '"water" "fruit"'), + array('\\', 'water\\"fruit"\\"air"'), + array('\\', '"water"\\"fruit"\\"""'), +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation18.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $csv_field = $csv_list[1]; + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blank line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use different delimiter than existing in file + fseek($file_handle, 0, SEEK_SET); + $del = "+"; + var_dump( fgetcsv($file_handle, 1024, $del) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with default enclosure and different delimiter *** + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation19.phpt b/ext/standard/tests/file/fgetcsv_variation19.phpt new file mode 100644 index 0000000000..2e282e1701 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation19.phpt @@ -0,0 +1,841 @@ +--TEST-- +Test fgetcsv() : usage variations - with default enclosure & delimiter of two chars +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* + Testing fgetcsv() to read a file when provided with default enclosure character + and with delimiter of two characters +*/ + +echo "*** Testing fgetcsv() : with default enclosure & delimiter of two chars ***\n"; + +/* the array is with two elements in it. Each element should be read as + 1st element is delimiter & 2nd element is csv fields +*/ +$csv_lists = array ( + array(',', 'water,fruit'), + array(' ', 'water fruit'), + array(' ', '"water" "fruit"'), + array('\\', 'water\\"fruit"\\"air"'), + array('\\', '"water"\\"fruit"\\"""'), +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation19.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $csv_field = $csv_list[1]; + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blank line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use delimiter & enclosure char of two chars + fseek($file_handle, 0, SEEK_SET); + $del = "++"; + var_dump( fgetcsv($file_handle, 1024, $del) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing fgetcsv() : with default enclosure & delimiter of two chars *** + +-- Testing fgetcsv() with file opened using r mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water,fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(11) "water fruit" +} +int(12) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(13) "water "fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(19) "water\"fruit"\"air"" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "water\"fruit"\"""" +} +int(20) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation2.phpt b/ext/standard/tests/file/fgetcsv_variation2.phpt new file mode 100644 index 0000000000..fc5947df50 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation2.phpt @@ -0,0 +1,1413 @@ +--TEST-- +Test fgetcsv() : usage variations - with length as 0 (Bug #42175) +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() to rwad from a file with length argument equal to zero */ + +echo "*** Testing fgetcsv() : with length as 0 ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation2.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blank line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use length as 0 + fseek($file_handle, 0, SEEK_SET); + var_dump( fgetcsv($file_handle, 0, $delimiter, $enclosure) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with length as 0 *** + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(11) "water=fruit" + [1]=> + string(0) "" +} +int(16) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(3) { + [0]=> + string(11) "water-fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(true) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation20.phpt b/ext/standard/tests/file/fgetcsv_variation20.phpt new file mode 100644 index 0000000000..e96089e9ab --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation20.phpt @@ -0,0 +1,191 @@ +--TEST-- +Test fgetcsv() : usage variations - with default enclosure, line without any csv fields +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* + Testing fgetcsv() to read a line without any csv fields from a file + when provided with default enclosure value +*/ + +echo "*** Testing fgetcsv() : with default enclosure, line without any csv fields ***\n"; + +$filename = dirname(__FILE__) . '/fgetcsv_variation20.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + // write line of text + fwrite($file_handle, "This is line of text without csv fields\n"); + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // read the line which is without csv fields, provide delimiter and see the working of fgetcsv + $fp_pos = ftell($file_handle); + var_dump( fgetcsv($file_handle, 1024) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with default enclosure, line without any csv fields *** + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(40) +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/fgetcsv_variation21.phpt b/ext/standard/tests/file/fgetcsv_variation21.phpt new file mode 100644 index 0000000000..69059bb2c9 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation21.phpt @@ -0,0 +1,191 @@ +--TEST-- +Test fgetcsv() : usage variations - with default enclosure, blank line +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* + Testing fgetcsv() to read a file containing blank line when provided with + default enclosure argument +*/ + +echo "*** Testing fgetcsv() : with default enclosure, blank line ***\n"; + +$filename = dirname(__FILE__) . '/fgetcsv_variation21.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + // write a blank line + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // read the line which is a blank line to see the working of fgetcsv + $fp_pos = ftell($file_handle); + var_dump( fgetcsv($file_handle, 1024, '+') ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with default enclosure, blank line *** + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(0) "" +} +int(1) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation22.phpt b/ext/standard/tests/file/fgetcsv_variation22.phpt new file mode 100644 index 0000000000..54cef3af86 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation22.phpt @@ -0,0 +1,614 @@ +--TEST-- +Test fgetcsv() : usage variations - with default enclosure, file pointer pointing at end of file (Bug #42175) +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* + Testing fgetcsv() to read a file whose file pointer is pointing to end of file + and fgetcsv() provided with default enclosure argument +*/ + +echo "*** Testing fgetcsv() : with default enclosure, file pointer pointing at end of file ***\n"; + +/* the array is with two elements in it. Each element should be read as + 1st element is delimiter & 2nd element is csv fields +*/ +$csv_lists = array ( + array(',', 'water,fruit'), + array(' ', 'water fruit'), + array(' ', '"water" "fruit"'), + array('\\', 'water\\"fruit"\\"air"'), + array('\\', '"water"\\"fruit"\\"""'), +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation22.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $csv_field = $csv_list[1]; + + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blan line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // set the file pointer to EOF + var_dump( fseek($file_handle, 0, SEEK_END) ); + + // call fgetcsv() to parse csv fields + + // now file pointer should point to end of the file, try reading again + var_dump( feof($file_handle) ); + var_dump( fgetcsv($file_handle, 1024, $delimiter) ); // with length, delimiter + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with default enclosure, file pointer pointing at end of file *** + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation23.phpt b/ext/standard/tests/file/fgetcsv_variation23.phpt new file mode 100644 index 0000000000..b766f1e062 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation23.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test fgetcsv() : usage variations - empty file +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() to read from an empty file */ + +echo "*** Testing fgetcsv() : reading from file which is having zero content ***\n"; + +// try reading from file which is having zero content +// create the file and then open in read mode and try reading +$filename = dirname(__FILE__) . '/fgetcsv_variation23.tmp'; +$fp = fopen ($filename, "w"); +fclose($fp); +$fp = fopen ($filename, "r"); +if (!$fp) { + echo "Error: failed to create file $filename!\n"; + exit(); +} +var_dump( fgetcsv($fp) ); +var_dump( ftell($fp) ); +var_dump( fgetcsv($fp, 1024) ); +var_dump( ftell($fp) ); +var_dump( fgetcsv($fp, 1024, "+" ) ); +var_dump( ftell($fp) ); +var_dump( fgetcsv($fp, 1024, "+", "%") ); +var_dump( ftell($fp) ); + +// close and delete the file +fclose($fp); +unlink($filename); +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : reading from file which is having zero content *** +bool(false) +int(0) +bool(false) +int(0) +bool(false) +int(0) +bool(false) +int(0) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation24.phpt b/ext/standard/tests/file/fgetcsv_variation24.phpt new file mode 100644 index 0000000000..89b6d03b90 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation24.phpt @@ -0,0 +1,671 @@ +--TEST-- +Test fgetcsv() : usage variations - two chars as enclosure & delimiter (various write modes) +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* + Testing fgetcsv() to read from a file opened in various write modes and + enclosure argument with two characters +*/ + +echo "*** Testing fgetcsv() : with two chars as enclosure & delimiter ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation24.tmp'; +@unlink($filename); + +$file_modes = array ("w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blank line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use delimiter & enclosure char of two chars + fseek($file_handle, 0, SEEK_SET); + $del = "++"; + $enc = "%%"; + var_dump( fgetcsv($file_handle, 1024, $del, $enc) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing fgetcsv() : with two chars as enclosure & delimiter *** + +-- Testing fgetcsv() with file opened using w+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Notice: fgetcsv(): delimiter must be a single character in %s on line %d + +Notice: fgetcsv(): enclosure must be a single character in %s on line %d +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation25.phpt b/ext/standard/tests/file/fgetcsv_variation25.phpt new file mode 100644 index 0000000000..1877bc0a0e --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation25.phpt @@ -0,0 +1,935 @@ +--TEST-- +Test fgetcsv() : usage variations - with negative length value along with enclosure and delimiter +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* + Testing fgetcsv() to read from a file when provided with negative length argument + along with delimiter and enclosure arguments +*/ + +echo "*** Testing fgetcsv() : with negative length value ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation25.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blank line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use the right delimiter and enclosure with negative length + var_dump( fgetcsv($file_handle, -10, $delimiter, $enclosure) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing fgetcsv() : with negative length value *** + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation26.phpt b/ext/standard/tests/file/fgetcsv_variation26.phpt new file mode 100644 index 0000000000..c042eb4931 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation26.phpt @@ -0,0 +1,441 @@ +--TEST-- +Test fgetcsv() : usage variations - reading files opened in write only mode (Bug #42036) +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() to read from files opened in write only mode */ + +echo "*** Testing fgetcsv() : reading the files opened in write only mode ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation26.tmp'; +@unlink($filename); + +$file_modes = array ("w", "wb", "wt", + "a", "ab", "at", + "x", "xb", "xt"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blank line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // rewind the file pointer to bof + rewind($file_handle); + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use the right delimiter and enclosure with max length + var_dump( fgetcsv($file_handle, 1024, $delimiter, $enclosure) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : reading the files opened in write only mode *** + +-- Testing fgetcsv() with file opened using w mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wt mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using ab mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using at mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xt mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wt mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using ab mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using at mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xt mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wt mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using ab mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using at mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xt mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wt mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using ab mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using at mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xt mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wt mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using ab mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using at mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xt mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wt mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using ab mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using at mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xt mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wt mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using ab mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using at mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xt mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using wt mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using ab mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using at mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xb mode -- +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using xt mode -- +bool(false) +int(0) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation27.phpt b/ext/standard/tests/file/fgetcsv_variation27.phpt new file mode 100644 index 0000000000..aafc3ab6c9 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation27.phpt @@ -0,0 +1,935 @@ +--TEST-- +Test fgetcsv() : usage variations - with negative length value along with delimiter and no enclosure +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* + Testing fgetcsv() to read from a file when provided with negative length argument + along with delimiter and no enclosure arguments +*/ + +echo "*** Testing fgetcsv() : with negative length value ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation27.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blank line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use the right delimiter and enclosure with negative length + var_dump( fgetcsv($file_handle, -10, $delimiter) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing fgetcsv() : with negative length value *** + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation28.phpt b/ext/standard/tests/file/fgetcsv_variation28.phpt new file mode 100644 index 0000000000..56dd538ac1 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation28.phpt @@ -0,0 +1,935 @@ +--TEST-- +Test fgetcsv() : usage variations - with negative length value along with neither enclosure and nor delimiter +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* + Testing fgetcsv() to read from a file when provided with negative length argument + along with neither delimiter nor enclosure argument +*/ + +echo "*** Testing fgetcsv() : with negative length value ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation28.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blank line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use the right delimiter and enclosure with negative length + var_dump( fgetcsv($file_handle, -10) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing fgetcsv() : with negative length value *** + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): Length parameter may not be negative in %s on line %d +bool(false) +int(0) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation29.phpt b/ext/standard/tests/file/fgetcsv_variation29.phpt new file mode 100644 index 0000000000..6ca5e87a1e --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation29.phpt @@ -0,0 +1,615 @@ +--TEST-- +Test fgetcsv() : usage variations - with only file handle as argument, file pointer pointing at end of file (Bug #42175) +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* + Testing fgetcsv() to read a file whose file pointer is pointing to end of file + and fgetcsv() provided with only file handle in its argument +*/ + +echo "*** Testing fgetcsv() : with file handle as only argument and file pointer pointing at end of file ***\n"; + +/* the array is with two elements in it. Each element should be read as + 1st element is delimiter & 2nd element is csv fields +*/ +$csv_lists = array ( + array(',', 'water,fruit'), + array(' ', 'water fruit'), + array(' ', '"water" "fruit"'), + array('\\', 'water\\"fruit"\\"air"'), + array('\\', '"water"\\"fruit"\\"""'), +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation29.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $csv_field = $csv_list[1]; + + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blan line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // set the file pointer to EOF + var_dump( fseek($file_handle, 0, SEEK_END) ); + + // call fgetcsv() to parse csv fields + + // now file pointer should point to end of the file, try reading again + var_dump( feof($file_handle) ); + var_dump( fgetcsv($file_handle) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with file handle as only argument and file pointer pointing at end of file *** + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation3.phpt b/ext/standard/tests/file/fgetcsv_variation3.phpt new file mode 100644 index 0000000000..52c094faa5 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation3.phpt @@ -0,0 +1,933 @@ +--TEST-- +Test fgetcsv() : usage variations - with delimiter as NULL +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() to read from a file when provided with delimiter value as NULL */ + +echo "*** Testing fgetcsv() : with delimiter as NULL ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation3.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blank line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use length as 0 + fseek($file_handle, 0, SEEK_SET); + var_dump( fgetcsv($file_handle, 1024, NULL, $enclosure) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing fgetcsv() : with delimiter as NULL *** + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation30.phpt b/ext/standard/tests/file/fgetcsv_variation30.phpt new file mode 100644 index 0000000000..c6e514da37 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation30.phpt @@ -0,0 +1,614 @@ +--TEST-- +Test fgetcsv() : usage variations - with file handle and length, file pointer pointing at end of file (Bug #42175) +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* + Testing fgetcsv() to read a file whose file pointer is pointing to end of file + and fgetcsv() provided with file handle and length arguments +*/ + +echo "*** Testing fgetcsv() : with file handle and length arguments, file pointer pointing at end of file ***\n"; + +/* the array is with two elements in it. Each element should be read as + 1st element is delimiter & 2nd element is csv fields +*/ +$csv_lists = array ( + array(',', 'water,fruit'), + array(' ', 'water fruit'), + array(' ', '"water" "fruit"'), + array('\\', 'water\\"fruit"\\"air"'), + array('\\', '"water"\\"fruit"\\"""'), +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation30.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $csv_field = $csv_list[1]; + + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blan line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // set the file pointer to EOF + var_dump( fseek($file_handle, 0, SEEK_END) ); + + // call fgetcsv() to parse csv fields + + // now file pointer should point to end of the file, try reading again + var_dump( feof($file_handle) ); + var_dump( fgetcsv($file_handle, 1024) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with file handle and length arguments, file pointer pointing at end of file *** + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation31.phpt b/ext/standard/tests/file/fgetcsv_variation31.phpt new file mode 100644 index 0000000000..5e042ac62d --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation31.phpt @@ -0,0 +1,616 @@ +--TEST-- +Test fgetcsv() : usage variations - with length and enclosure, file pointer pointing at end of file (Bug #42175) +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* + Testing fgetcsv() to read a file whose file pointer is pointing to end of file + and fgetcsv() provided with enclosure argument +*/ + +echo "*** Testing fgetcsv() : with enclosure argument, file pointer pointing at end of file ***\n"; + +/* the array is with two elements in it. Each element should be read as + 1st element is delimiter & 2nd element is csv fields +*/ +$csv_lists = array ( + array(',', 'water,fruit'), + array(' ', 'water fruit'), + array(' ', '"water" "fruit"'), + array('\\', 'water\\"fruit"\\"air"'), + array('\\', '"water"\\"fruit"\\"""'), +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation31.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $csv_field = $csv_list[1]; + + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blan line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // set the file pointer to EOF + var_dump( fseek($file_handle, 0, SEEK_END) ); + + // call fgetcsv() to parse csv fields + + // now file pointer should point to end of the file, try reading again + var_dump( feof($file_handle) ); + $enc = 'z'; + var_dump( fgetcsv($file_handle, 1024, $delimiter, $enc ) ); // with length, delimiter + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with enclosure argument, file pointer pointing at end of file *** + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(53) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(57) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rb mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using rt mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using r+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using a+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using w+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+ mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+b mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) + +-- Testing fgetcsv() with file opened using x+t mode -- +int(0) +bool(true) +bool(false) +int(61) +bool(true) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation4.phpt b/ext/standard/tests/file/fgetcsv_variation4.phpt new file mode 100644 index 0000000000..0c84484721 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation4.phpt @@ -0,0 +1,932 @@ +--TEST-- +Test fgetcsv() : usage variations - with enclosure as NULL +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() to read from a file when provided with enclosure value as NULL */ + +echo "*** Testing fgetcsv() : with enclosure as NULL ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation4.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blan line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use length as 0 + fseek($file_handle, 0, SEEK_SET); + var_dump( fgetcsv($file_handle, 0, $delimiter, NULL) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing fgetcsv() : with enclosure as NULL *** + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): enclosure must be a character in %s on line %d +bool(false) +int(0) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation5.phpt b/ext/standard/tests/file/fgetcsv_variation5.phpt new file mode 100644 index 0000000000..283fa40bd8 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation5.phpt @@ -0,0 +1,934 @@ +--TEST-- +Test fgetcsv() : usage variations - with delimiter & enclosure as NULL +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* + Testing fgetcsv() to read from a file when provided with delimiter and + enclosure values both as NULL + */ + +echo "*** Testing fgetcsv() : with delimiter & enclosure as NULL ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation5.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blank line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + fseek($file_handle, 0, SEEK_SET); + var_dump( fgetcsv($file_handle, 1024, NULL, NULL) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing fgetcsv() : with delimiter & enclosure as NULL *** + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- + +Warning: fgetcsv(): delimiter must be a character in %s on line %d +bool(false) +int(0) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation6.phpt b/ext/standard/tests/file/fgetcsv_variation6.phpt new file mode 100644 index 0000000000..9878cb98d2 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation6.phpt @@ -0,0 +1,2350 @@ +--TEST-- +Test fgetcsv() : usage variations - with length less than line size +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* + Testing fgetcsv() to read from a file when provided with the length argument + value less than the line size +*/ + +echo "*** Testing fgetcsv() : with length less than line size ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation6.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blan line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use length as less than the actual size of the line + fseek($file_handle, 0, SEEK_SET); + var_dump( fgetcsv($file_handle, 9, $delimiter, $enclosure) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + // read rest of the line + var_dump( fgetcsv($file_handle, 1024, $delimiter, $enclosure) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with length less than line size *** + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(1) "f" +} +int(9) +bool(false) +array(1) { + [0]=> + string(4) "ruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(1) "f" +} +int(9) +bool(false) +array(1) { + [0]=> + string(4) "ruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(1) "f" +} +int(9) +bool(false) +array(1) { + [0]=> + string(4) "ruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(1) "f" +} +int(9) +bool(false) +array(1) { + [0]=> + string(4) "ruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(1) "f" +} +int(9) +bool(false) +array(1) { + [0]=> + string(4) "ruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(1) "f" +} +int(9) +bool(false) +array(1) { + [0]=> + string(4) "ruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(1) "f" +} +int(9) +bool(false) +array(1) { + [0]=> + string(4) "ruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(1) "f" +} +int(9) +bool(false) +array(1) { + [0]=> + string(4) "ruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(1) "f" +} +int(9) +bool(false) +array(1) { + [0]=> + string(4) "ruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(1) "f" +} +int(9) +bool(false) +array(1) { + [0]=> + string(4) "ruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(1) "f" +} +int(9) +bool(false) +array(1) { + [0]=> + string(4) "ruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(1) "f" +} +int(9) +bool(false) +array(1) { + [0]=> + string(4) "ruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(1) "f" +} +int(9) +bool(false) +array(1) { + [0]=> + string(4) "ruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(1) "f" +} +int(9) +bool(false) +array(1) { + [0]=> + string(4) "ruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(1) "f" +} +int(9) +bool(false) +array(1) { + [0]=> + string(4) "ruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(8) { + [0]=> + string(4) "This" + [1]=> + string(2) "is" + [2]=> + string(4) "line" + [3]=> + string(2) "of" + [4]=> + string(4) "text" + [5]=> + string(7) "without" + [6]=> + string(3) "csv" + [7]=> + string(6) "fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(56) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(6) "water=" +} +int(9) +bool(false) +array(2) { + [0]=> + string(5) "fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(6) "water=" +} +int(9) +bool(false) +array(2) { + [0]=> + string(5) "fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(6) "water=" +} +int(9) +bool(false) +array(2) { + [0]=> + string(5) "fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(6) "water=" +} +int(9) +bool(false) +array(2) { + [0]=> + string(5) "fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(6) "water=" +} +int(9) +bool(false) +array(2) { + [0]=> + string(5) "fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(6) "water=" +} +int(9) +bool(false) +array(2) { + [0]=> + string(5) "fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(6) "water=" +} +int(9) +bool(false) +array(2) { + [0]=> + string(5) "fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(6) "water=" +} +int(9) +bool(false) +array(2) { + [0]=> + string(5) "fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(6) "water=" +} +int(9) +bool(false) +array(2) { + [0]=> + string(5) "fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(6) "water=" +} +int(9) +bool(false) +array(2) { + [0]=> + string(5) "fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(6) "water=" +} +int(9) +bool(false) +array(2) { + [0]=> + string(5) "fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(6) "water=" +} +int(9) +bool(false) +array(2) { + [0]=> + string(5) "fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(6) "water=" +} +int(9) +bool(false) +array(2) { + [0]=> + string(5) "fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(6) "water=" +} +int(9) +bool(false) +array(2) { + [0]=> + string(5) "fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(6) "water=" +} +int(9) +bool(false) +array(2) { + [0]=> + string(5) "fruit" + [1]=> + string(0) "" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(58) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(58) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(58) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(58) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(58) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(58) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(58) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(58) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(58) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(58) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(58) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(58) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(58) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(58) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(58) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(6) "water-" +} +int(9) +bool(false) +array(3) { + [0]=> + string(5) "fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(6) "water-" +} +int(9) +bool(false) +array(3) { + [0]=> + string(5) "fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(6) "water-" +} +int(9) +bool(false) +array(3) { + [0]=> + string(5) "fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(6) "water-" +} +int(9) +bool(false) +array(3) { + [0]=> + string(5) "fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(6) "water-" +} +int(9) +bool(false) +array(3) { + [0]=> + string(5) "fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(6) "water-" +} +int(9) +bool(false) +array(3) { + [0]=> + string(5) "fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(6) "water-" +} +int(9) +bool(false) +array(3) { + [0]=> + string(5) "fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(6) "water-" +} +int(9) +bool(false) +array(3) { + [0]=> + string(5) "fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(6) "water-" +} +int(9) +bool(false) +array(3) { + [0]=> + string(5) "fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(6) "water-" +} +int(9) +bool(false) +array(3) { + [0]=> + string(5) "fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(6) "water-" +} +int(9) +bool(false) +array(3) { + [0]=> + string(5) "fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(6) "water-" +} +int(9) +bool(false) +array(3) { + [0]=> + string(5) "fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(6) "water-" +} +int(9) +bool(false) +array(3) { + [0]=> + string(5) "fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(6) "water-" +} +int(9) +bool(false) +array(3) { + [0]=> + string(5) "fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(6) "water-" +} +int(9) +bool(false) +array(3) { + [0]=> + string(5) "fruit" + [1]=> + string(3) "air" + [2]=> + string(0) "" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(64) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(64) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(64) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(64) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(64) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(64) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(64) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(64) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(64) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(64) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(64) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(64) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(64) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(64) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(6) { + [0]=> + string(4) """""" + [1]=> + string(1) """ + [2]=> + string(1) "," + [3]=> + string(1) """ + [4]=> + string(1) "," + [5]=> + string(4) ",,,," +} +int(24) +bool(false) +array(1) { + [0]=> + string(39) "This is line of text without csv fields" +} +int(64) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation7.phpt b/ext/standard/tests/file/fgetcsv_variation7.phpt new file mode 100644 index 0000000000..723328e086 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation7.phpt @@ -0,0 +1,1292 @@ +--TEST-- +Test fgetcsv() : usage variations - with default arguments value +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* Testing fgetcsv() to read from a file when provided with default value of arguments */ + +echo "*** Testing fgetcsv() : with default arguments value ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation7.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blank line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use only default arguments + fseek($file_handle, 0, SEEK_SET); + var_dump( fgetcsv($file_handle) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with default arguments value *** + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(2) { + [0]=> + string(5) "water" + [1]=> + string(5) "fruit" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(7) { + [0]=> + string(11) "&""""&:&"&:" + [1]=> + string(4) ":":&" + [2]=> + string(2) "&:" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(7) { + [0]=> + string(11) "&""""&:&"&:" + [1]=> + string(4) ":":&" + [2]=> + string(2) "&:" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(7) { + [0]=> + string(11) "&""""&:&"&:" + [1]=> + string(4) ":":&" + [2]=> + string(2) "&:" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(7) { + [0]=> + string(11) "&""""&:&"&:" + [1]=> + string(4) ":":&" + [2]=> + string(2) "&:" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(7) { + [0]=> + string(11) "&""""&:&"&:" + [1]=> + string(4) ":":&" + [2]=> + string(2) "&:" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(7) { + [0]=> + string(11) "&""""&:&"&:" + [1]=> + string(4) ":":&" + [2]=> + string(2) "&:" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(7) { + [0]=> + string(11) "&""""&:&"&:" + [1]=> + string(4) ":":&" + [2]=> + string(2) "&:" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(7) { + [0]=> + string(11) "&""""&:&"&:" + [1]=> + string(4) ":":&" + [2]=> + string(2) "&:" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(7) { + [0]=> + string(11) "&""""&:&"&:" + [1]=> + string(4) ":":&" + [2]=> + string(2) "&:" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(7) { + [0]=> + string(11) "&""""&:&"&:" + [1]=> + string(4) ":":&" + [2]=> + string(2) "&:" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(7) { + [0]=> + string(11) "&""""&:&"&:" + [1]=> + string(4) ":":&" + [2]=> + string(2) "&:" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(7) { + [0]=> + string(11) "&""""&:&"&:" + [1]=> + string(4) ":":&" + [2]=> + string(2) "&:" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(7) { + [0]=> + string(11) "&""""&:&"&:" + [1]=> + string(4) ":":&" + [2]=> + string(2) "&:" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(7) { + [0]=> + string(11) "&""""&:&"&:" + [1]=> + string(4) ":":&" + [2]=> + string(2) "&:" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(7) { + [0]=> + string(11) "&""""&:&"&:" + [1]=> + string(4) ":":&" + [2]=> + string(2) "&:" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" +} +int(24) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation8.phpt b/ext/standard/tests/file/fgetcsv_variation8.phpt new file mode 100644 index 0000000000..21b6c88752 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation8.phpt @@ -0,0 +1,1058 @@ +--TEST-- +Test fgetcsv() : usage variations - with different delimiter and enclosure +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* + Testing fgetcsv() to read from a file when provided with values of delimiter and + enclosure that are not present in the line read by fgetcsv() +*/ + +echo "*** Testing fgetcsv() : with different delimiter and enclosure ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation8.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blank line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use different delimiter and enclosure than existing in file + fseek($file_handle, 0, SEEK_SET); + $del = "+"; + $enc = "%"; + var_dump( fgetcsv($file_handle, 1024, $del, $enc) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with different delimiter and enclosure *** + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(13) ""water",fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(15) ""water","fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(15) "^water^ ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(15) "&water&:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(15) "=water===fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(17) "-water--fruit-air" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(21) "-water---fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(23) "&""""&:&"&:,:":&,&:,,,," +} +int(24) +bool(false) +Done diff --git a/ext/standard/tests/file/fgetcsv_variation9.phpt b/ext/standard/tests/file/fgetcsv_variation9.phpt new file mode 100644 index 0000000000..6400fc84e3 --- /dev/null +++ b/ext/standard/tests/file/fgetcsv_variation9.phpt @@ -0,0 +1,1056 @@ +--TEST-- +Test fgetcsv() : usage variations - with different delimiter but same enclosure +--FILE-- +<?php +/* + Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] ); + Description: Gets line from file pointer and parse for CSV fields +*/ + +/* + Testing fgetcsv() to read from a file when the delimiter argument value is not + present in the line being read by the fgetcsv() +*/ + +echo "*** Testing fgetcsv() : with different delimiter but same enclosure ***\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 +*/ +$csv_lists = array ( + array(',', '"', '"water",fruit'), + array(',', '"', '"water","fruit"'), + array(' ', '^', '^water^ ^fruit^'), + array(':', '&', '&water&:&fruit&'), + array('=', '=', '=water===fruit='), + array('-', '-', '-water--fruit-air'), + array('-', '-', '-water---fruit---air-'), + array(':', '&', '&""""&:&"&:,:":&,&:,,,,') +); + +$filename = dirname(__FILE__) . '/fgetcsv_variation9.tmp'; +@unlink($filename); + +$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", + "a+", "a+b", "a+t", + "w+", "w+b", "w+t", + "x+", "x+b", "x+t"); + +$loop_counter = 1; +foreach ($csv_lists as $csv_list) { + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + // create the file and add the content with has csv fields + if ( strstr($file_modes[$mode_counter], "r") ) { + $file_handle = fopen($filename, "w"); + } else { + $file_handle = fopen($filename, $file_modes[$mode_counter] ); + } + if ( !$file_handle ) { + echo "Error: failed to create file $filename!\n"; + exit(); + } + $delimiter = $csv_list[0]; + $enclosure = $csv_list[1]; + $csv_field = $csv_list[2]; + fwrite($file_handle, $csv_field . "\n"); + // write another line of text and a blank line + // this will be used to test, if the fgetcsv() read more than a line and its + // working when only a blan line is read + fwrite($file_handle, "This is line of text without csv fields\n"); + fwrite($file_handle, "\n"); // blank line + + // close the file if the mode to be used is read mode and re-open using read mode + // else rewind the file pointer to begining of the file + if ( strstr($file_modes[$mode_counter], "r" ) ) { + fclose($file_handle); + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } else { + // rewind the file pointer to bof + rewind($file_handle); + } + + echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; + + // call fgetcsv() to parse csv fields + + // use different delimiter but same enclosure char + fseek($file_handle, 0, SEEK_SET); + $del = "+"; + var_dump( fgetcsv($file_handle, 1024, $del, $enclosure) ); + // check the file pointer position and if eof + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + + // close the file + fclose($file_handle); + //delete file + unlink($filename); + } //end of mode loop +} // end of foreach + +echo "Done\n"; +?> +--EXPECT-- +*** Testing fgetcsv() : with different delimiter but same enclosure *** + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(11) "water,fruit" +} +int(14) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(13) "water,"fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(13) "water,"fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(13) "water,"fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(13) "water,"fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(13) "water,"fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(13) "water,"fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(13) "water,"fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(13) "water,"fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(13) "water,"fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(13) "water,"fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(13) "water,"fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(13) "water,"fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(13) "water,"fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(13) "water,"fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(13) "water,"fruit"" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(13) "water ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(13) "water ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(13) "water ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(13) "water ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(13) "water ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(13) "water ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(13) "water ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(13) "water ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(13) "water ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(13) "water ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(13) "water ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(13) "water ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(13) "water ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(13) "water ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(13) "water ^fruit^" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(13) "water:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(13) "water:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(13) "water:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(13) "water:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(13) "water:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(13) "water:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(13) "water:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(13) "water:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(13) "water:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(13) "water:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(13) "water:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(13) "water:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(13) "water:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(13) "water:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(13) "water:&fruit&" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(12) "water=fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(12) "water=fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(12) "water=fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(12) "water=fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(12) "water=fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(12) "water=fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(12) "water=fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(12) "water=fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(12) "water=fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(12) "water=fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(12) "water=fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(12) "water=fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(12) "water=fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(12) "water=fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(12) "water=fruit=" +} +int(16) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(14) "water-fruitair" +} +int(18) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(18) "water-fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(18) "water-fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(18) "water-fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(18) "water-fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(18) "water-fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(18) "water-fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(18) "water-fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(18) "water-fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(18) "water-fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(18) "water-fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(18) "water-fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(18) "water-fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(18) "water-fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(18) "water-fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(18) "water-fruit---air-" +} +int(22) +bool(false) + +-- Testing fgetcsv() with file opened using r mode -- +array(1) { + [0]=> + string(21) """"":&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using rb mode -- +array(1) { + [0]=> + string(21) """"":&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using rt mode -- +array(1) { + [0]=> + string(21) """"":&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+ mode -- +array(1) { + [0]=> + string(21) """"":&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+b mode -- +array(1) { + [0]=> + string(21) """"":&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using r+t mode -- +array(1) { + [0]=> + string(21) """"":&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+ mode -- +array(1) { + [0]=> + string(21) """"":&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+b mode -- +array(1) { + [0]=> + string(21) """"":&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using a+t mode -- +array(1) { + [0]=> + string(21) """"":&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+ mode -- +array(1) { + [0]=> + string(21) """"":&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+b mode -- +array(1) { + [0]=> + string(21) """"":&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using w+t mode -- +array(1) { + [0]=> + string(21) """"":&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+ mode -- +array(1) { + [0]=> + string(21) """"":&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+b mode -- +array(1) { + [0]=> + string(21) """"":&"&:,:":&,&:,,,," +} +int(24) +bool(false) + +-- Testing fgetcsv() with file opened using x+t mode -- +array(1) { + [0]=> + string(21) """"":&"&:,:":&,&:,,,," +} +int(24) +bool(false) +Done |