note 22582 added to function.fgetcsv

From: Date: Mon, 24 Jun 2002 00:21:07 +0000
Subject: note 22582 added to function.fgetcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-32134@lists.php.net to get a copy of this message
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. function check_csv_field_ref(&$item) { $item = str_replace('"', '""', $item); if (strpos($item, ",") !== FALSE) { $item = '"' . $item . '"'; } } -- http://www.php.net/manual/en/function.fgetcsv.php http://master.php.net/manage/user-notes.php?action=edit+22582 http://master.php.net/manage/user-notes.php?action=delete+22582 http://master.php.net/manage/user-notes.php?action=reject+22582

« previous php.notes (#32134) next »