note 116077 deleted from function.fgetcsv by salathe
| From: | salathe@php.net | Date: | Fri, 07 Nov 2014 11:17:53 +0000 |
| Subject: | note 116077 deleted from function.fgetcsv by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-200838@lists.php.net to get a copy of this message | ||
Note Submitter: quickshiftin at gmail dot com
----
Following up on Tim Henderson's note; I stumbled into this the hard way as well myself. Seems
fputcsv is pretty broken in that fgetcsv accepts an $escape parameter, but fputcsv does not.
You're left to roll your own (horribly slow) $escape handler in userspace code to properly
implement fputcsv...
/**
* int fputcsv ( resource $handle , array $fields [, string $delimiter = "," [, string
$enclosure = '"', [, string $escape = "\\" ]]] )
*/
function not_broken_fputcsv($handle, array $fields, $delimiter=',',
$enclosure='"', $escape='\\')
{
foreach($fields as &$sField)
if($sField == $escape)
$sField = $escape . $sField;
return fputcsv($handle, $fields, $delimiter, $enclosure, $escape);
}