troubleshooting Question

PHP strip quotes and line feeds out of array

Avatar of mitai
mitaiFlag for Canada asked on
PHPMySQL Server
12 Comments1 Solution1357 ViewsLast Modified:
I have code that pulls data from infusionsoft api and writes it to a csv file.  the issue is the data isn't all that clean in the database and some strings have double quotes surrounding the data.  Other strings have a line feed character in the data.  When it writes out to the csv and i try to bring it into excel these characters effect the data.  See code below.   what i want to do is after the data is read into the array, step through the array and remove the quotes and line feeds before it moves to the csv.  Can someone help me with this?  My code is below
do {
  if(in_array('Id', $object_fields)){
    $results = Infusionsoft_DataService::queryWithOrderBy($object, array('Id' => '%'), 'Id', true, 500, $page );
  } else {
    $results = Infusionsoft_DataService::queryWithOrderBy($object, array($object_fields[0] => '%'), $object_fields[0], true, 500, $page );
  }

  foreach($results as $result) {
    fputcsv($csv_file, $result->toArray(), "^", "\"");
  }
  $page++;
} while(count($results) > 0);
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros