123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- --TEST--
- various fgetcsv() functionality tests
- --FILE--
- <?php
- $list = array(
- 'aaa,bbb',
- 'aaa,"bbb"',
- '"aaa","bbb"',
- 'aaa,bbb',
- '"aaa",bbb',
- '"aaa", "bbb"',
- ',',
- 'aaa,',
- ',"aaa"',
- '"",""',
- '"\\"","aaa"',
- '"""""",',
- '""""",aaa' . "\n",
- '"\\""",aaa' . "\n",
- 'aaa,"\\"bbb,ccc' . "\n",
- 'aaa,bbb ',
- 'aaa,"bbb "',
- 'aaa"aaa","bbb"bbb',
- 'aaa"aaa""",bbb',
- 'aaa"\\"a","bbb"',
- 'aaa,"bbb' . "\n",
- 'aaa,"bbb',
- );
- $file = __DIR__ . '/fgetcsv.csv';
- @unlink($file);
- foreach ($list as $v) {
- $fp = fopen($file, "w");
- fwrite($fp, $v);
- fclose($fp);
- var_dump(fgetcsv(fopen($file, "r"), 1024));
- }
- @unlink($file);
- ?>
- --EXPECT--
- array(2) {
- [0]=>
- string(3) "aaa"
- [1]=>
- string(3) "bbb"
- }
- array(2) {
- [0]=>
- string(3) "aaa"
- [1]=>
- string(3) "bbb"
- }
- array(2) {
- [0]=>
- string(3) "aaa"
- [1]=>
- string(3) "bbb"
- }
- array(2) {
- [0]=>
- string(3) "aaa"
- [1]=>
- string(3) "bbb"
- }
- array(2) {
- [0]=>
- string(3) "aaa"
- [1]=>
- string(3) "bbb"
- }
- array(2) {
- [0]=>
- string(3) "aaa"
- [1]=>
- string(3) "bbb"
- }
- array(2) {
- [0]=>
- string(0) ""
- [1]=>
- string(0) ""
- }
- array(2) {
- [0]=>
- string(3) "aaa"
- [1]=>
- string(0) ""
- }
- array(2) {
- [0]=>
- string(0) ""
- [1]=>
- string(3) "aaa"
- }
- array(2) {
- [0]=>
- string(0) ""
- [1]=>
- string(0) ""
- }
- array(2) {
- [0]=>
- string(2) "\""
- [1]=>
- string(3) "aaa"
- }
- array(2) {
- [0]=>
- string(2) """"
- [1]=>
- string(0) ""
- }
- array(1) {
- [0]=>
- string(7) """,aaa
- "
- }
- array(1) {
- [0]=>
- string(8) "\"",aaa
- "
- }
- array(2) {
- [0]=>
- string(3) "aaa"
- [1]=>
- string(10) "\"bbb,ccc
- "
- }
- array(2) {
- [0]=>
- string(3) "aaa"
- [1]=>
- string(6) "bbb "
- }
- array(2) {
- [0]=>
- string(3) "aaa"
- [1]=>
- string(6) "bbb "
- }
- array(2) {
- [0]=>
- string(8) "aaa"aaa""
- [1]=>
- string(6) "bbbbbb"
- }
- array(2) {
- [0]=>
- string(10) "aaa"aaa""""
- [1]=>
- string(3) "bbb"
- }
- array(2) {
- [0]=>
- string(8) "aaa"\"a""
- [1]=>
- string(3) "bbb"
- }
- array(2) {
- [0]=>
- string(3) "aaa"
- [1]=>
- string(4) "bbb
- "
- }
- array(2) {
- [0]=>
- string(3) "aaa"
- [1]=>
- string(3) "bbb"
- }
|