explode()We can break a string and create an array out of it by using a delimiter. Here is its syntax
We can specify the delimiter and 2nd parameter is the string we want to break and third parameter is optional by which we can fix the number of elements of the array. Let us try some examples. We have used print_r function to display the elements of the array we get out of our explode function.
We have used one space as delimiter. The output is here
We don't want more than three elements to in the array then change the code like this.
Output is here
Breaking an email address using explodeWe can use explode function to separate userid part and domain part from an email address . Let us try this example.
We have used @ as delimiter in above code. Here is the output
Learn more on breaking email address here
Breaking the URL of a pageThe URL of a page consist of domain name, directory name and file name. These are joined by / to create path to the page we execute. The Path of the url pointing to this page is here.
Now using explode function we will break the above url to separate domain part, directory and the file name.
Here is the code.
The output is here
To get a single output we can use like this