note 98401 deleted from function.str-getcsv by danbrown
| From: | danbrown@php.net | Date: | Sun, 13 Jun 2010 02:25:59 +0000 |
| Subject: | note 98401 deleted from function.str-getcsv by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170093@lists.php.net to get a copy of this message | ||
Note Submitter: updates at mail dot ru
----
This function sometimes incorrect work with csv-files produced by Excel 2007.
I'm wrote shortly and correct analog:
function csv2array($s)
{
preg_match_all('/(("([^"]|"")*")|(((?<=;)|(?<=^))[^";]*))(;|$)/u',
$s, $m);
// check format
$n = 0;
foreach($m[0] as $l) $n += mb_strlen($l);
// incorrect format
if ($n != mb_strlen($s)) return false;
foreach($m[1] as &$l)
if (mb_substr($l, 0, 1)=='"')
$l = str_replace('""', '"', mb_substr($l, 1, -1));
return $m[1];
}