I need to split my string input into an array at the commas.
How can I go about accomplishing this?
Input:
9,[email protected],8
I need to split my string input into an array at the commas.
How can I go about accomplishing this?
9,[email protected],8
$string = '9,[email protected],8';
$array = explode(',', $string);
For more complicated situations, you may need to use preg_split
.
If that string comes from a csv file, I would use fgetcsv()
(or str_getcsv()
if you have PHP V5.3). That will allow you to parse quoted values correctly. If it is not a csv, explode()
should be the best choice.