madThumbs Posted July 17, 2009 Share Posted July 17, 2009 :confused: Hey guys, really need your help here. I am try to split the following string into an array by comma, however, as you can see the sample below, in the [1] there are already a comma inside the sub string, which I don't want to split apart, so how can I layout this in regx, please help me out here. Thank you very much. $row_data = '16603, "Lay's, Inc", 2505 Anthem Village Dr. E-525, 12/15/2008 ' ; Ideal result: Array { [0] =>16603 [1] =>"Lay's, Inc" [2] =>2505 Anthem Village Dr. E-525 [3] =>12/15/2008 } what I got by split only by comma Array { [0] => 16603 [1] => "Lay's [2] => Inc" [3] => 2505 Anthem Village Dr. E-525 [4] =>12/15/2008 } Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted July 17, 2009 Share Posted July 17, 2009 You can use preg_split to accomplish this: $row_data = '16603, "Lay\'s, Inc", 2505 Anthem Village Dr. E-525, 12/15/2008 ' ; $arr = preg_split('#,\s{2,}#', $row_data); $arr = array_map('trim', $arr); echo '<pre>'.print_r($arr, true); //Output: //Array //( // [0] => 16603 // [1] => "Lay's, Inc" // [2] => 2505 Anthem Village Dr. E-525 // [3] => 12/15/2008 //) Quote Link to comment Share on other sites More sharing options...
madThumbs Posted July 17, 2009 Author Share Posted July 17, 2009 Thanks you very much :D Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted July 17, 2009 Share Posted July 17, 2009 Your welcome Please flag this thread as 'Topic Solved'. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.