Say I have a string like this: $string = 'Micheal, Smith, 31, "Corona, California", dentist'; Code (markup): I want to split this string so that I have an array like this: $myarray[0] = 'Michael'; $myarray[1] = 'Smith'; $myarray[2] = 21; $myarray[3] = 'Corona, California'; $myarray[4] = 'dentist'; How do I go about doing this? if I do: $myarray= explode(",", $string); I will get this: $myarray[0] = 'Michael'; $myarray[1] = 'Smith'; $myarray[2] = 21; $myarray[3] = '[COLOR="Red"]"[/COLOR]Corona'; $myarray[4] = 'California[COLOR="Red"]"[/COLOR]'; $myarray[5] = 'dentist'; Code (markup): ANy help will be gladly appreciated! Thanks!
There you go: $myarray = preg_split( "/[\s,]*\\\"([^\\\"]+)\\\"[\s,]*|[\s,]+/", $string, 0, PREG_SPLIT_DELIM_CAPTURE ); PHP: hth