How can I split a delimited string into an array in PHP?

Kevin picture Kevin · Jul 14, 2009 · Viewed 448.8k times · Source

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

Answer

Matthew Groves picture Matthew Groves · Jul 14, 2009

Try explode:

$myString = "9,[email protected],8";
$myArray = explode(',', $myString);
print_r($myArray);

Output :

Array
(
    [0] => 9
    [1] => [email protected]
    [2] => 8
)