What is difference between explode() or split() in PHP?

devquora
devquora

Posted On: Feb 22, 2018

 

The explode() and split() functions are used in PHP to split the strings. Both are defined here:

Split() is used to split a string into an array using a regular expression whereas explode() is used to split the string by string using the delimiter.

Example of split():

split(":", "this:is:a:split"); //returns an array that contains this, is, a, split.

Output: Array ([0] => this,[1] => is,[2] => a,[3] => split)

Example of explode():

explode ("take", "take a explode example "); //returns an array which have value "a explode example"

Output: array([0] => "a explode example")

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    PHP Interview Questions

    What is T_PAAMAYIM_NEKUDOTAYIM in PHP?

    T_PAAMAYIM_NEKUDOTAYIM is scope resolution operator used as :: (double colon) .Basically, it used to call static methods/variables of a Class...

    PHP Interview Questions

    What is the difference between == and === operator in PHP ?

    In PHP == is equal operator and returns TRUE if $a is equal to $b after type juggling and === is Identical operator and return TRUE if $a is equal to $b, and they are of the same data type...