Put data to CSV headers

Hi, I’m a complete newbe to CSV files. I am trying to find out how to send data from any source, and have that data get put into its respective columns, i.e. - Address, Date, etc. Also, how do I go about making the headers in the first place. I have tried fputcsv() function, but that just seems to write to the fields.
Is there like a CSV site?

Please Help…


All you have to do is make sure your data is in the right structure (i.e. an array of arrays - one per row of data).
If you want a header row, just make sure that the first row is an array of column names:

$data = array (
    array('last_name', 'first_name', 'age', 'gender'),    // The header row
    array('Smith', 'John', 28, 'Male'),
    array('Doe', 'Jane', 36, 'Female')

to write the data to a CSV file:

$fp = fopen('file.csv', 'w');

foreach ($data as $fields) {
    fputcsv($fp, $fields);


Check the PHP manual page on [fphp]fputcsv[/fphp] for more detail.