I need to split my string input into an array at the commas.
Is there a way to explode a comma-separated string into a flat, indexed array?
Input:
9,[email protected],8
Output:
['9', 'admin@example', '8']
Answer: Use the split() Method You can use the JavaScript split() method to split a string using a specific separator such as comma ( , ), space, etc. If separator is an empty string, the string is converted to an array of characters.
To split a string with comma, use the split() method in Java. str. split("[,]", 0);
Given a long string separated with comma delimiter. The task is to split the given string with comma delimiter and store the result in an array. Use explode() or preg_split() function to split the string in php with given delimiter.
In order to parse a comma-delimited String, you can just provide a "," as a delimiter and it will return an array of String containing individual values. The split() function internally uses Java's regular expression API (java. util. regex) to do its job.
Try explode:
$myString = "9,[email protected],8"; $myArray = explode(',', $myString); print_r($myArray);
Output :
Array ( [0] => 9 [1] => [email protected] [2] => 8 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With