note 121080 deleted from function.explode by salathe

From: Date: Mon, 21 Sep 2020 14:49:26 +0000
Subject: note 121080 deleted from function.explode by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215331@lists.php.net to get a copy of this message
Note Submitter: MarkAgius at markagius dot co dot uk ---- As you can not send an enclosure value to explode, use str_getcsv, if you want to explode a string when the delimiter is in some cells. (Comma in quotes) <?php $a = "aaa1,bbb1,'ccc,ccc1',ddd1"; $b = 'aaa2,bbb2,"ccc,ccc2",ddd2'; // This dosn't work as it splits 'ccc,ccc1' and "ccc,ccc2". print "<PRE>a output using explode():\n"; print_r( explode(",",$a) ); print "</PRE>\n"; print "<PRE>b output using explode():\n"; print_r( explode(",",$b) ); print "</PRE>\n"; // This works. print "<PRE>a output using str_getcsv():\n"; print_r( str_getcsv($a,",","'") ); print "</PRE>\n"; print "<PRE>b output using str_getcsv():\n"; print_r( str_getcsv($b,",","\"") ); print "</PRE>\n"; ?> explode() returns; [0] => aaa1 [1] => bbb1 [2] => 'ccc [3] => ccc1' [4] => ddd1 str_getcsv() returns; [0] => aaa1 [1] => bbb1 [2] => ccc,ccc1 [3] => ddd1

« previous php.notes (#215331) next »