note 22582 deleted from function.fgetcsv by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 09:03:00 +0000 |
| Subject: | note 22582 deleted from function.fgetcsv by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196855@lists.php.net to get a copy of this message | ||
Note Submitter: c dot greenNOSP at Mits dot uq dot edu dot au
----
Quoting csv is pretty simple, and there are two steps..I note in previous comments only the second
step has been explained.
First fields with double quotes need to double up the quotes, ie _He said "Timmy"..._
should become _He said ""Timmy""..._
Secondly as mentioned above, fields with commas need double quotes.
Here is a simple function to achieve this, that I pass to array walk, if you want to use it
somewhere else, prob get rid of reference and return the value.
<?php
function check_csv_field_ref(&$item) {
$item = str_replace('"', '""', $item);
if (strpos($item, ",") !== FALSE) {
$item = '"' . $item . '"';
}
}
?>