note 115556 deleted from function.fgetcsv by salathe
| From: | salathe@php.net | Date: | Fri, 22 Aug 2014 08:11:19 +0000 |
| Subject: | note 115556 deleted from function.fgetcsv by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-200268@lists.php.net to get a copy of this message | ||
Note Submitter: vladimir dot fesko at gmail dot com
----
The problem with \" character sequence appears when blackslash is treated as an escape
character, so it parses the characters \" as a backslash-escaped double quote.
The fix this (PHP 5.3.0+): we need to tell fgetcsv() not to use backslash as an escape character by
passing other character as the $escape parameter to it. Unfortunately, passing null, false or
'' (empty string) don't work. For me it worked when passed the same character as
$enclosure (double quote for example) '"':
<?php
$handle = fopen('file.csv', 'r');
$row = fgetcsv($handle, null, ";", '"', '"'); // Disable
escape character
print_r($row);
fclose($handle);
?>