Split a string by string- using explode in php
Split a string by string
Syntax : array explode ( string $delimiter , string $string [, int $limit ] )
Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter .
Parameters :
delimiter : The boundary string.
String : The input string.
Limit : If limit is set, the returned array will contain a maximum of limit elements with the last element containing the rest of string .
If the limit parameter is negative, all components except the last -limit are returned.
Return Values :
If delimiter is an empty string (“”), explode() will return FALSE. If delimiter contains a value that is not contained in string , then explode() will return an array containing string
Example :
<?php
$rawPhoneNumber = "800-555-5555";
$phoneChunks = explode("-", $rawPhoneNumber);
echo "Raw Phone Number = $rawPhoneNumber <br />";
echo "First chunk = $phoneChunks[0]<br />";
echo "Second chunk = $phoneChunks[1]<br />";
echo "Third Chunk chunk = $phoneChunks[2]";
?>
Display:
Raw Phone Number = 800-555-5555
First chunk = 800
Second chunk = 555
Third Chunk chunk = 5555




