note 116093 deleted from function.fputcsv by peehaa

From: Date: Fri, 09 Dec 2016 22:33:24 +0000
Subject: note 116093 deleted from function.fputcsv by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208360@lists.php.net to get a copy of this message
Note Submitter: quickshiftin at gmail dot com ---- Unlike fgetcsv, fputcsv doesn't provide an $escape parameter. This can lead to trouble if you write files using fputcsv, later to be read by fgetcsv. For example if you're using the default backslash escape character from fgetcsv and you've written it to a file using fputcsv, the file will not be correctly read by fgetcsv. Here's a wrapper for fputcsv that adds an $escape parameter. /** * 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) $sField = str_replace($escape, $escape . $escape, $sField); return fputcsv($handle, $fields, $delimiter, $enclosure, $escape); }

« previous php.notes (#208360) next »