Hi Brendan, You should get away with just quoting your values that will have commas in the content. There are probably better ways of doing this tho... Cheers Dave T
$csv_output .= $order['product_code'].' " '. etc.... -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Brendan Brink Sent: Thursday, 23 September 2010 10:35 a.m. To: [email protected] Subject: [phpug] CSV exporting using PHP Hi there all, Using PHP to export to CSV files on the fly - and wondered what the best practice was to do in this regard... currently, im creating a variable to store the data to be exported as such $csv_output .= $order['product_code']." ".$order['product_description'].",".$store['supplier_name'].",".$order['product_quantity'].",".$order['import_format_time'].",$".$order['unit_cost'].","."$".round($order['unit_cost']*$order['product_quantity'],2)."\n"; seperated by commas, terminated with new line and then exporting as such: $out = ''; if (isset($_POST['csv_hdr'])) { $out .= $_POST['csv_hdr']; $out .= "\n"; } if (isset($_POST['csv_output'])) { $out .= $_POST['csv_output']; } $filename = str_replace(" ","_",$_POST['csv_name']); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header("Content-disposition: filename=".$filename.".csv"); print $out; /// issue i am facing is that the data that is being exported to the CSV file is entered by other users and may include commas in the text, or in the total currency amounts, eg. $42,000 what is the best way to prevent any and all errors from happening in this regard, I tried using the semicolon, but this didnt seem to export well. any suggestions or assistance would be most appreciated... cheers brendan. -- NZ PHP Users Group: http://groups.google.com/group/nzphpug To post, send email to [email protected] To unsubscribe, send email to [email protected] Warning: This email contains information which is CONFIDENTIAL and may also be LEGALLY PRIVILEGED. If you are not the intended recipient you must not peruse, use, disseminate, distribute or copy this email or attachments. If you have received this in error, please notify us immediately by return email and delete this email. Thank you. ##################################################################################### This e-mail message has been scanned for Viruses and Content and cleared by MailMarshal ##################################################################################### -- NZ PHP Users Group: http://groups.google.com/group/nzphpug To post, send email to [email protected] To unsubscribe, send email to [email protected]
