Jump to content

Removing commas in csv file


bmccue

Recommended Posts

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

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;

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;

 

 

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.