PHP split() Function


Hello dear readers! welcome back to another section of our tutorial on PHP. In this tutorial guide, we will be discussing about the PHP split() Function.

The split() function will divide a string into various elements, the boundaries of each element in string based on the occurrence of pattern in string.

The optional input parameter limit is used to signify the number number of elements into which the string needs to be divided, starting from the left end of the string and moving rightward.

In cases where the pattern is an alphabetical character, the split() is case sensitive.

RECOMMENDED POST: PHP eregi_replace() Function


The following is the syntax for the split() function -

array split (string pattern, string string  [, int limit]);

Return Value

  • Returns an array of strings after splitting up a string.


Following is a simple example -


   $ip = "123.456.789.000"; // some IP address
   $iparr = split ("\.", $ip); 
   print "$iparr[0] <br />";
   print "$iparr[1] <br />" ;
   print "$iparr[2] <br />"  ;
   print "$iparr[3] <br />"  ;



When the above code is executed, it will produce the following result -



Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial post, we will be discussing about the PHP spliti() Function.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.