I have a piece of php code that reads values from a database resultset, shoves them into an array, and writes them to a CSV file. I need to force each value to be surrounded by double quotes when it goes into the CSV file, and can't for the life of me remember how to do this.
Here's the loop that writes to the file (this is actually contained in another loop to go through each row; this loop I'm showing goes through the columns in the currently-selected row):
foreach ($row as $key => $val){
$newrow[$key] = preg_replace("(
|
||\t)", "", $val);
}
fputcsv($fp, $newrow);
What I need is for the value of $val to be enclosed in double quotes when it's written to the file. Right now, the results I get look like this:
554,702180,25.00,6FYAK0,9090909090909090
What I need is this:
"554","702180","25.00","6FYAK0","9090909090909090"
Can someone jump start my brain?