Jump to content

Create a new CSV file from my PHP generated data?


Cep

Recommended Posts

Hello,

I was wondering if it is actually possible to create a brand new CSV file using PHP so that I can then write my data to it. I know and have used functions to read in CSV's and edit pre-existing ones files but I don't beleive I have ever seen anything that allows me create a brand new CSV file and populate it.

Any pointers?

And as a side note has anyone got a similar method for working on brand new XML files? (Though I suppose I could cheat and get php to write XML directly into a text file).
If you just write to a file like you normally do in php using fopen, fwrite, fclose or your perfered method and format as you would expect in a CSV file and then just save in as a CSV file.

or something like below should work too.

[code]

<?php

header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename='.$cv_name);
header('Cache-Control: max-age=0, must-revalidate');

echo $data['field_1'].",".$data['field_2'].",".$data['field_3'].",".$data['field_4'].",,,,,,,,,,,,,,,,,,,,,,,,,,/n\r";

?>

[/code]

  • 1 month later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.