note 105853 added to function.preg-match-all
| From: | satyavvd at ymail dot com | Date: | Tue, 20 Sep 2011 11:08:11 +0000 |
| Subject: | note 105853 added to function.preg-match-all | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183290@lists.php.net to get a copy of this message | ||
Extract fields out of csv string : ( since before php5.3 you can't use str_getcsv function )
Here is the regex :
<?php
$csvData = <<<EOF
10,'20',"30","'40","'50'","\"60","70,80","09\\/18,/\"2011",'a,sdfcd'
EOF
$reg = <<<EOF
/
(
(
([\'\"])
(
(
[^\'\"]
|
(\\\\.)
)*
)
(\\3)
|
(
[^,]
|
(\\\\.)
)*
),)
/x
EOF;
preg_match_all($reg,$csvData,$matches);
// to extract csv fields
print_r($matches[2]);
----
Server IP: 69.147.83.197
Probable Submitter: 203.110.238.16
----
Manual Page -- http://www.php.net/manual/en/function.preg-match-all.php
Edit -- https://master.php.net/note/edit/105853
Del: integrated -- https://master.php.net/note/delete/105853/integrated
Del: useless -- https://master.php.net/note/delete/105853/useless
Del: bad code -- https://master.php.net/note/delete/105853/bad+code
Del: spam -- https://master.php.net/note/delete/105853/spam
Del: non-english -- https://master.php.net/note/delete/105853/non-english
Del: in docs -- https://master.php.net/note/delete/105853/in+docs
Del: other reasons-- https://master.php.net/note/delete/105853
Reject -- https://master.php.net/note/reject/105853
Search -- https://master.php.net/manage/user-notes.php