macinslaw Posted June 19, 2007 Share Posted June 19, 2007 I need to be able to generate the file without using double quotes in the resultant file. Please assist. -Macinslaw Link to comment https://forums.phpfreaks.com/topic/56198-using-php-to-generate-a-csv-file/ Share on other sites More sharing options...
LuciBKen Posted June 19, 2007 Share Posted June 19, 2007 Here's a generic script for writing to a csv file, it should give you what you need. //saving record in a text file $pfw_file_name = "yourfile.csv"; $pfw_first_raw = "textfield,textarea,file,file2\r\n"; $pfw_values = "$textfield,".str_replace ("\r\n","<BR>",$textarea ).",$file_Name,$file2_Name\r\n"; $pfw_is_first_row = false; if(!file_exists($pfw_file_name)) { $pfw_is_first_row = true ; } if (!$pfw_handle = fopen($pfw_file_name, 'a+')) { die("Cannot open file ($pfw_file_name)"); exit; } if ($pfw_is_first_row) { if (fwrite($pfw_handle, $pfw_first_raw ) === FALSE) { die("Cannot write to file ($pfw_filename)"); exit; } } if (fwrite($pfw_handle, $pfw_values) === FALSE) { die("Cannot write to file ($pfw_filename)"); exit; } fclose($pfw_handle); Link to comment https://forums.phpfreaks.com/topic/56198-using-php-to-generate-a-csv-file/#findComment-277583 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.