Difference Between Split and Explode in PHP

The split() and explode() are two main string function in php, if you are working in php, you would have used this function on your application. You have also faced some question in interview regarding difference between php split and explode string function. In this post, I will let you know what are difference between Split and Explode with example.

Simple Usage and example of split() PHP function

The split() function splits the string into an array using a regular expression and returns an array. PHP split function takes three arguments, first one takes pattern regular expression which is case sensitive, second is input string and thirst one is for limit: If the limit is set, the returned array will contain a maximum of limit elements with the last element containing the whole rest of string.

How to use PHP split Function

Output :

Warning
This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0.Alternatives to this function include:

Simple Usage and Example of explode() PHP function

The php explode() function splits the string using delimiter and returns an array. PHP explode function takes three argument, first one takes delimiter as a argument, second one is target string and third one is limit : If limit is set and positive, the returned array will contain a maximum of limit elements with the last element containing the rest of string.

Simple Example and Demo of PHP explode function

Output

Leave a Reply

Your email address will not be published. Required fields are marked *