1--TEST-- 2SplFileObject::fputcsv(): functionality tests 3--FILE-- 4<?php 5$file = __DIR__ . '/SplFileObject_fputcsv.csv'; 6$fo = new SplFileObject($file, 'w'); 7 8$list = array ( 9 0 => 'aaa,bbb', 10 1 => 'aaa,"bbb"', 11 2 => '"aaa","bbb"', 12 3 => 'aaa,bbb', 13 4 => '"aaa",bbb', 14 5 => '"aaa", "bbb"', 15 6 => ',', 16 7 => 'aaa,', 17 8 => ',"aaa"', 18 9 => '"",""', 19 10 => '"""""",', 20 11 => '""""",aaa', 21 12 => 'aaa,bbb ', 22 13 => 'aaa,"bbb "', 23 14 => 'aaa"aaa","bbb"bbb', 24 15 => 'aaa"aaa""",bbb', 25 16 => 'aaa,"\\"bbb,ccc', 26 17 => 'aaa"\\"a","bbb"', 27 18 => '"\\"","aaa"', 28 19 => '"\\""",aaa', 29); 30 31foreach ($list as $v) { 32 $fo->fputcsv(explode(',', $v)); 33} 34unset($fo); 35 36$res = file($file); 37foreach($res as &$val) 38{ 39 $val = substr($val, 0, -1); 40} 41echo '$list = ';var_export($res);echo ";\n"; 42 43$fp = fopen($file, "r"); 44$res = array(); 45while($l=fgetcsv($fp)) 46{ 47 $res[] = join(',',$l); 48} 49fclose($fp); 50 51echo '$list = ';var_export($res);echo ";\n"; 52 53?> 54===DONE=== 55<?php exit(0); ?> 56--CLEAN-- 57<?php 58$file = __DIR__ . '/SplFileObject_fputcsv.csv'; 59unlink($file); 60?> 61--EXPECT-- 62$list = array ( 63 0 => 'aaa,bbb', 64 1 => 'aaa,"""bbb"""', 65 2 => '"""aaa""","""bbb"""', 66 3 => 'aaa,bbb', 67 4 => '"""aaa""",bbb', 68 5 => '"""aaa"""," ""bbb"""', 69 6 => ',', 70 7 => 'aaa,', 71 8 => ',"""aaa"""', 72 9 => '"""""",""""""', 73 10 => '"""""""""""""",', 74 11 => '"""""""""""",aaa', 75 12 => 'aaa,"bbb "', 76 13 => 'aaa,"""bbb """', 77 14 => '"aaa""aaa""","""bbb""bbb"', 78 15 => '"aaa""aaa""""""",bbb', 79 16 => 'aaa,"""\\"bbb",ccc', 80 17 => '"aaa""\\"a""","""bbb"""', 81 18 => '"""\\"""","""aaa"""', 82 19 => '"""\\"""""",aaa', 83); 84$list = array ( 85 0 => 'aaa,bbb', 86 1 => 'aaa,"bbb"', 87 2 => '"aaa","bbb"', 88 3 => 'aaa,bbb', 89 4 => '"aaa",bbb', 90 5 => '"aaa", "bbb"', 91 6 => ',', 92 7 => 'aaa,', 93 8 => ',"aaa"', 94 9 => '"",""', 95 10 => '"""""",', 96 11 => '""""",aaa', 97 12 => 'aaa,bbb ', 98 13 => 'aaa,"bbb "', 99 14 => 'aaa"aaa","bbb"bbb', 100 15 => 'aaa"aaa""",bbb', 101 16 => 'aaa,"\\"bbb,ccc', 102 17 => 'aaa"\\"a","bbb"', 103 18 => '"\\"","aaa"', 104 19 => '"\\""",aaa', 105); 106===DONE=== 107