fputcsv() formats a line (passed as a fields array) as CSV and write it (terminated by a newline) to the specified file handle.
The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()).
An array of values.
The optional delimiter parameter sets the field delimiter (one character only).
The optional enclosure parameter sets the field enclosure (one character only).
The optional escape_char parameter sets the escape character (one character only).
Returns the length of the written string or FALSE on failure.
The escape_char parameter was added
<?php
$list = array (
array('aaa', 'bbb', 'ccc', 'dddd'),
array('123', '456', '789'),
array('"aaa"', '"bbb"')
);
$fp = fopen('file.csv', 'w');
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
?>
The above example will write the following to file.csv:
aaa,bbb,ccc,dddd 123,456,789 """aaa""","""bbb"""
Please login to continue.