bmccue Posted February 19, 2010 Share Posted February 19, 2010 I am very new to this and I am trying to remove the commas from the address fields (ship address 1, 2 &3) in the csv file generated by this code. The commas are causing the data to appear in the wrong fields. <?php { $header = 'Ticket,Membr,ShipName,ShipAddress1,ShipAddress2,ShipAddress3,ShipCity,ShipState,ShipZip,ShipCountry,PKGTYPE,Shipping,WEIGHT,BILLTRANSTO,Total,Email,Phone,SHIPMETHOD,SHIPFROM,FromComp,Attn,FromPhone,FromAddr,FromCity,FromZip,FromState,QVN,QVNMemo,FromEmail,Notes'."\r\n"; $pkgtype = 'CP'; $weight=0; $billtran='SHIP'; $shipmethod='GROUND'; $query = 'SELECT * from ecs_ord WHERE date_shipped<"1970-00-00"'; $db->execute($query); foreach($db->result as $o){ $line = array($o['ord_id'],$o['userid'],$o['first_name_shipto'].' '.$o['last_name_shipto'],$o['address1_shipto'],$o['address2_shipto'],$o['address3_shipto'], $o['city_shipto'],$o['state_shipto'],$o['zip_shipto'],$o['country_shipto'],$pkgtype,$o['ship_cost'],$weight,$billtran,$o['total_payment'],$o['email_billto'],$o['phone_billto'],$shipmethod); $header .= implode(',',$line).$common; } header("Content-type:application/vnd.ms-excel"); header('Content-Disposition: attachment; filename="UPS_Shipfile.csv"'); echo $header; } else {echo "Must be an Admin to Use this Menu";} ?> Any help is appreciated! Thanks. Link to comment https://forums.phpfreaks.com/topic/192649-removing-commas-in-csv-file/ Share on other sites More sharing options...
SchweppesAle Posted February 19, 2010 Share Posted February 19, 2010 Use fputcsv() and fgetcsv() instead. http://php.net/manual/en/function.fputcsv.php Link to comment https://forums.phpfreaks.com/topic/192649-removing-commas-in-csv-file/#findComment-1014896 Share on other sites More sharing options...
bmccue Posted February 22, 2010 Author Share Posted February 22, 2010 Thanks, but I'm not really sure how to go about doing this. Link to comment https://forums.phpfreaks.com/topic/192649-removing-commas-in-csv-file/#findComment-1016145 Share on other sites More sharing options...
bmccue Posted February 23, 2010 Author Share Posted February 23, 2010 Here was my solution: foreach($db->result as $o){ $o['ord_id']=str_replace (',',' ',$o['ord_id']); $o['userid']=str_replace (',',' ',$o['userid']); $o['first_name_shipto'].''.$o['last_name_shipto']=str_replace (',',' ',$o['first_name_shipto'].' '.$o['last_name_shipto']); $o['address1_shipto']=str_replace (',',' ',$o['address1_shipto']); $o['address2_shipto']=str_replace (',',' ',$o['address2_shipto']); $o['address3_shipto']=str_replace (',',' ',$o['address3_shipto']); $o['city_shipto']=str_replace (',',' ',$o['city_shipto']); $o['state_shipto']=str_replace (',',' ',$o['state_shipto']); $o['zip_shiptp']=str_replace (',',' ',$o['zip_shipto']); $o['country_shipto']=str_replace (',',' ',$o['country_shipto']); $o['ship_cost']=str_replace (',',' ',$o['ship_cost']); $o['total_payment']=str_replace (',',' ',$o['total_payment']); $o['email_billto']=str_replace (',',' ',$o['email_billto']); $o['phone_billto']=str_replace (',',' ',$o['phone_billto']); $line = array($o['ord_id'],$o['userid'],$o['first_name_shipto'].' '.$o['last_name_shipto'],$o['address1_shipto'],$o['address2_shipto'],$o['address3_shipto'], $o['city_shipto'],$o['state_shipto'],$o['zip_shipto'],$o['country_shipto'],$pkgtype,$o['ship_cost'],$weight,$billtran,$o['total_payment'],$o['email_billto'],$o['phone_billto'],$shipmethod); $header .= implode(',',$line).$common; Link to comment https://forums.phpfreaks.com/topic/192649-removing-commas-in-csv-file/#findComment-1016920 Share on other sites More sharing options...
bmccue Posted February 23, 2010 Author Share Posted February 23, 2010 Sorry. That one didn't work. this one did. foreach($db->result as $o){ $o['ord_id']=str_replace (',',' ',$o['ord_id']); $o['userid']=str_replace (',',' ',$o['userid']); $o['address1_shipto']=str_replace (',',' ',$o['address1_shipto']); $o['address2_shipto']=str_replace (',',' ',$o['address2_shipto']); $o['address3_shipto']=str_replace (',',' ',$o['address3_shipto']); $o['city_shipto']=str_replace (',',' ',$o['city_shipto']); $o['state_shipto']=str_replace (',',' ',$o['state_shipto']); $o['zip_shiptp']=str_replace (',',' ',$o['zip_shipto']); $o['country_shipto']=str_replace (',',' ',$o['country_shipto']); $o['ship_cost']=str_replace (',',' ',$o['ship_cost']); $o['total_payment']=str_replace (',',' ',$o['total_payment']); $o['email_billto']=str_replace (',',' ',$o['email_billto']); $o['phone_billto']=str_replace (',',' ',$o['phone_billto']); $firstlastname=str_replace (',',' ',$o['first_name_shipto'].' '.$o['last_name_shipto']); $line = array($o['ord_id'],$o['userid'],$firstlastname,$o['address1_shipto'],$o['address2_shipto'],$o['address3_shipto'], $o['city_shipto'],$o['state_shipto'],$o['zip_shipto'],$o['country_shipto'],$pkgtype,$o['ship_cost'],$weight,$billtran,$o['total_payment'],$o['email_billto'],$o['phone_billto'],$shipmethod); $header .= implode(',',$line).$common; Link to comment https://forums.phpfreaks.com/topic/192649-removing-commas-in-csv-file/#findComment-1017049 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.