Cep Posted December 7, 2006 Share Posted December 7, 2006 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). Link to comment https://forums.phpfreaks.com/topic/29788-create-a-new-csv-file-from-my-php-generated-data/ Share on other sites More sharing options...
mjlogan Posted December 7, 2006 Share Posted December 7, 2006 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]<?phpheader('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] Link to comment https://forums.phpfreaks.com/topic/29788-create-a-new-csv-file-from-my-php-generated-data/#findComment-136794 Share on other sites More sharing options...
Cep Posted December 7, 2006 Author Share Posted December 7, 2006 Is that not assuming I already have a file though to use fopen with? I need to create a completely new file to be created as nothing exists at first. Link to comment https://forums.phpfreaks.com/topic/29788-create-a-new-csv-file-from-my-php-generated-data/#findComment-136800 Share on other sites More sharing options...
trq Posted December 7, 2006 Share Posted December 7, 2006 [url=http://php.net/fopen]fopen[/url] can create a new file if one does not exist. Link to comment https://forums.phpfreaks.com/topic/29788-create-a-new-csv-file-from-my-php-generated-data/#findComment-136823 Share on other sites More sharing options...
Cep Posted December 7, 2006 Author Share Posted December 7, 2006 Ah! good good, thats all I needed to know :) Thanks guys! Link to comment https://forums.phpfreaks.com/topic/29788-create-a-new-csv-file-from-my-php-generated-data/#findComment-136881 Share on other sites More sharing options...
trochia Posted January 17, 2007 Share Posted January 17, 2007 Hello, I have a question... I have a routine that does this, but I would like to have it create a new file when the end of month is up. Could someone help me please? thank-you in advance,jim Link to comment https://forums.phpfreaks.com/topic/29788-create-a-new-csv-file-from-my-php-generated-data/#findComment-163053 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.