Query: fputcsv
OS: php
Section: 3
Format: Original Unix Latex Style Formatted with HTML and a Horizontal Scroll Bar
FPUTCSV(3) 1 FPUTCSV(3) fputcsv - Format line as CSV and write to file pointerSYNOPSISint fputcsv (resource $handle, array $fields, [string $delimiter = ","], [string $enclosure = '"'], [string $escape_char = "DESCRIPTIONfputcsv(3) formats a line (passed as a $fields array) as CSV and write it (terminated by a newline) to the specified file $handle.PARAMETERSo $handle -The file pointer must be valid, and must point to a file successfully opened by fopen(3) or fsockopen(3) (and not yet closed by fclose(3)). o $fields - An array of values. o $delimiter - The optional $delimiter parameter sets the field delimiter (one character only). o $enclosure - The optional $enclosure parameter sets the field enclosure (one character only). o $escape_char - The optional $escape_char parameter sets the escape character (one character only).RETURN VALUESReturns the length of the written string or FALSE on failure.CHANGELOG+--------+---------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------+ | 5.5.4 | | | | | | | The $escape_char parameter was added | | | | +--------+---------------------------------------+EXAMPLESExample #1 fputcsv(3) example <?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"""NOTESNote If PHP is not properly recognizing the line endings when reading files either on or created by a Macintosh computer, enabling the auto_detect_line_endings run-time configuration option may help resolve the problem.SEE ALSOfgetcsv(3). PHP Documentation Group FPUTCSV(3)