(PHP 5 >= 5.1.0)
fputcsv — Format line as CSV and write to file pointer
fputcsv() formats a line (passed as a fields array) as CSV and write it (terminated by a newline) to the specified file handle .
Indicatorul fişierului trebuie să fie valid şi trebuie să indice la un fişier deschis cu succes cu ajutorul fopen() sau fsockopen() (şi să nu fie închis cu fclose()).
An array of values.
The optional delimiter parameter sets the field delimiter (one character only). Defaults as a comma: ,.
The optional enclosure parameter sets the field enclosure (one character only) and defaults to a double quotation mark: ".
Returns the length of the written string, or FALSE on failure.
Example#1 fputcsv() example
<?php
$list = array (
'aaa,bbb,ccc,dddd',
'123,456,789',
'"aaa","bbb"'
);
$fp = fopen('file.csv', 'w');
foreach ($list as $line) {
fputcsv($fp, split(',', $line));
}
fclose($fp);
?>
Notă: Dacă aveţi probleme de genul: PHP nu recunoaşte terminaţia liniilor când citeşte fişiere create, sau aflate pe un computer Macintosh, atunci ar trebui să activaţi opţiunea de configurare la rulare auto_detect_line_endings.