Home » » fputcsv

fputcsv

Written By 1 on Sunday, September 30, 2012 | 6:57 PM

int fputcsv ( resource $handle , array $fields [, string $delimiter = ',' [, string $enclosure = '"' ]] )

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.


<?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);
?>


PHP Tutorial: Using CSV Files [part 02]

0 Comment:

Post a Comment