fputcsv
fputcsv
Format line as CSV and write to file pointer
**fputcsv** resource $stream array $fields string $separator string $enclosure string $escape string $eol
formats a line (passed as a
array) as and writes it
(terminated by a ) to the specified
.
fputcsv``fields``eol``stream
stream``fields
An array of s.
string
eol
The optional parameter sets
a custom End of Line sequence.
eol
Opmerking: > If an character is contained in a field, it will be escaped by doubling it, unless it is immediately preceded by an .
enclosure``escape
Returns the length of the written string return.falseforfailure.
Voorbeeld: example
<?php
$list = [
['aaa', 'bbb', 'ccc', 'dddd'],
['123', '456', '789'],
['"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"""
fgetcsv``str_getcsv``SplFileObject::fgetcsv``SplFileObject::fputcsv``SplFileObject::setCsvControl``SplFileObject::getCsvControl