1--TEST-- 2fputcsv() variant where escape parameter matters 3--FILE-- 4<?php 5 6$list = [ 7 1 => 'aaa,"/"bbb,ccc', 8 2 => 'aaa"/"a","bbb"', 9 3 => '"/"","aaa"', 10 4 => '"/""",aaa', 11]; 12 13$file = __DIR__ . '/fputcsv_variation18.csv'; 14 15$fp = fopen($file, "w"); 16foreach ($list as $v) { 17 fputcsv($fp, explode(',', $v), ',', '"', '/'); 18} 19fclose($fp); 20 21$res = file($file); 22foreach($res as &$val) 23{ 24 $val = substr($val, 0, -1); 25} 26echo '$list = ';var_export($res);echo ";\n"; 27 28$fp = fopen($file, "r"); 29$res = array(); 30while($l=fgetcsv($fp, 0, ',', '"', '/')) 31{ 32 $res[] = join(',',$l); 33} 34fclose($fp); 35 36echo '$list = ';var_export($res);echo ";\n"; 37 38?> 39--CLEAN-- 40<?php 41$file = __DIR__ . '/fputcsv_variation18.csv'; 42@unlink($file); 43?> 44--EXPECTF-- 45$list = array ( 46 0 => 'aaa,"""/"bbb",ccc', 47 1 => '"aaa""/"a""","""bbb"""', 48 2 => '"""/"""","""aaa"""', 49 3 => '"""/"""""",aaa', 50); 51$list = array ( 52 0 => 'aaa,"/"bbb,ccc', 53 1 => 'aaa"/"a","bbb"', 54 2 => '"/"","aaa"', 55 3 => '"/""",aaa', 56); 57