PHP Explode comma separated values with date -


i'm using explode parse string of comma separated values variables. no problem there. issue i'm having 1 of values date in format: may 3, 2013. explode picking on comma in date. have options getting around this? don't have control on source (the original string) i'm trying come way work i've got.

$content = 'blue,red,purple,may 2, 2013,orange,green'; list($valuea, $valueb, $valuec, $valued, $valuee, $valuef) = explode(',', $content); 

thank you!

you can use regex split string. based on assumption, there not whitespace between 2 words if used seperator.

$content = 'blue,red,purple,may 2, 2013,orange,green'; $result = preg_split('/,(?! )/', $content); 

your string result correctly in

array(6) {    [0]=>       string(4) "blue"    [1]=>       string(3) "red"    [2]=>       string(6) "purple"    [3]=>       string(11) "may 2, 2013"    [4]=>       string(6) "orange"    [5]=>      string(5) "green" } 

so once using list expression again, variables should set correctly

list($valuea, $valueb, $valuec, $valued, $valuee, $valuef) = preg_split('/,(?! )/', $content); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -