Change language

Split a comma separated string into an array in PHP

| |
Examples:
Input: engineer, for, engineer Output: Array ([0] = > engineer [1] = > for [2] = > engineer) Input: practice, code Output: Array ([0] = > practice [1] = > code) 
Use explode() or preg_split() to split a line in php with a given delimiter. PHP | Explode() function :explode() function - it is a built-in function in PHP that is used to split a string into different lines. The explode() function splits the string based on the string delimiter, that is, it splits the string where the delimiter character is encountered. This function returns an array containing strings formed by splitting the original string. 
Syntax:
array explode (separator, OriginalString, NoOfElements) 
PHP | Preg_split() function: preg_split() function works exactly like split(), except that regular expressions are accepted as input parameters for the template.Syntax:
array preg_split (string $pattern, string $subject [, int $limit = -1 [, int $flags = 0]]) 
Example :  
// Use the preg_split() function $string = "123,456,78,000" ; $str_arr = preg_split ( "/ , / " , $string ); print_r ( $str_arr );  
// use explosion $string = "123,46,78,000" ; $str_arr = explode ( "," , $string ); print_r ( $str_arr ); ?>
Exit:
Array ([ 0] = > 123 [1] = > 456 [2] = > 78 [3] = > 000) Array ([0] = > 123 [1] = > 46 [2] = > 78 [3] = > 000) 

Split a comma separated string into an array in PHP PHP: Questions

Split a comma separated string into an array in PHP sep: Questions

Shop

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method