The split() and explode() are two main string function in php. The split() function splits the string into an array using a regular expression and returns an array. PHP split function takes three arguments, first parameter is 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.
split(":", "this:is:a:string"); //returns an array that contains this, is, a, string.
output:
Array(
[0] => this,
[1] => is,
[2] => a,
[3] => string
)
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.
explode ("this", "this is a string"); //returns an array that contains array "is a string"
output:
array([0] => "is a string")