note 116093 added to function.fputcsv

From: Date: Sat, 08 Nov 2014 18:48:40 +0000
Subject: note 116093 added to function.fputcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-200849@lists.php.net to get a copy of this message
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); } ---- Server IP: 72.52.91.14 Probable Submitter: 50.243.157.62 ---- Manual Page -- http://php.net/manual/en/function.fputcsv.php Edit -- https://master.php.net/note/edit/116093 Del: integrated -- https://master.php.net/note/delete/116093/integrated Del: useless -- https://master.php.net/note/delete/116093/useless Del: bad code -- https://master.php.net/note/delete/116093/bad+code Del: spam -- https://master.php.net/note/delete/116093/spam Del: non-english -- https://master.php.net/note/delete/116093/non-english Del: in docs -- https://master.php.net/note/delete/116093/in+docs Del: other reasons-- https://master.php.net/note/delete/116093 Reject -- https://master.php.net/note/reject/116093 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200849) next »