PHP explode() Function Example Tutorial

This article will provide example of php explode function. I’m going to show you about php explode string to array. it’s simple example of php split string to array using explode. This article will give you simple example of explode function in php example.

The PHP explode() function breaks a string into an array. explode() takes a three argument separator, string and limit. limit is a optional.

Let’s see below syntax and example:

Syntax:

explode(separator,string,limit)

.medrectangle-3-multi-157{border:none!important;display:block!important;float:none;line-height:0;margin-bottom:15px!important;margin-left:0!important;margin-right:0!important;margin-top:15px!important;max-width:100%!important;min-height:250px;min-width:300px;padding:0;text-align:center!important}

Example 1:

index.php

<?php

$myString = "Hi, I am ItSolutionStuff.com";

$array = explode(' ', $myString);

print_r($array);

Output:

Array

(

[0] => Hi,

[1] => I

[2] => am

[3] => ItSolutionStuff.com

)

Example 2:.medrectangle-4-multi-155{border:none!important;display:block!important;float:none;line-height:0;margin-bottom:15px!important;margin-left:0!important;margin-right:0!important;margin-top:15px!important;max-width:100%!important;min-height:250px;min-width:300px;padding:0;text-align:center!important}

index.php

<?php

$myString = "Rajkot,Surat,Bhavnagar,Baroda";

$array = explode(',', $myString, 3);

print_r($array);

Output:

Array

(

[0] => Rajkot

[1] => Surat

[2] => Bhavnagar

)

I hope it can help you…

Leave a Comment