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.
Input : geeks,for,geeks Output : Array (  => geeks  => for  => geeks ) Input : practice, code Output : Array (  => practice  => code )
Use explode() or preg_split() function to split the string in php with given delimiter.
PHP | explode() Function: The explode() function is an inbuilt function in PHP which is used to split a string in different strings. The explode() function splits a string based on a string delimiter, i.e. it splits the string wherever the delimiter character occurs. This functions returns an array containing the strings formed by splitting the original string.
array explode( separator, OriginalString, NoOfElements )
PHP | preg_split() Function: The preg_split() function operates exactly like split(), except that regular expressions are accepted as input parameters for pattern.
array preg_split( string $pattern, string $subject [, int $limit = -1 [, int $flags = 0 ]] )
Array (  => 123  => 456  => 78  => 000 ) Array (  => 123  => 46  => 78  => 000 )
- How to put string in array, split by new line in PHP ?
- PHP | Program to check a string is a rotation of another string
- What is the difference between array_merge and array + array in PHP?
- How to get the last n characters of a PHP string?
- How to check if URL contain certain string using PHP?
- PHP | Reverse a String
- PHP | String Functions
- PHP | Different characters in the given string
- String comparison using == vs strcmp() in PHP
- How to remove extension from string in PHP?
- How to convert string to boolean in PHP?
- How to convert a string into number in PHP?
- PHP | strtok() for tokening string
- Generating Random String Using PHP
- PHP to check substring in a string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.