PHP String explode

Explode is a very usefull php function to split s string to an array of strings by the string delimiter.
for example you have a sentence that you want to get its words, means to explode this sentence to an array of words, just like that:
String: "I will go to USA the next week"
make it an array:
"I" , "will" , "go" , "to" , "USA" , "the" , "next" , "week"

This is how it works:
<?php

$string = 'I will go to USA the next week' ;
$array = explode ( ' ' , $string ) ; // This will split $string by the space character ' '
echo $array[0] ; // Display: I
echo $array[1] ; // Display: will
echo $array[2] ; // Display: go
echo $array[3] ; // Display: to
echo $array[4] ; // Display: USA

?>
In explode parameters, you need to enter the delimiter string ( which is space in this example, and it can be any other string), and the string you want to explode.
This function returns an array of small strings.

You can also explode the string to many string, rather than an array.
<?php

$string = '125:145:165:175' ;
list($string1 , $string2 , $string3 , $string4 ) = explode ( ':' , $string ) ; // This will explode
echo $string1 ; // Display: 125
echo $string2 ; // Display: 145
echo $string3 ; // Display: 165
echo $string4 ; // Display: 175

?>

PHP explode() is also usefull for time and date, explode time "08:16:00" to get hours, minutes and seconds and explode date to get year, day and month.

2 comments:

D3 Gold said...

The minute card is definitely beautiful -- along with what a pleasant present. Virtually any lady will be thrilled to get this.
Thanks for an individual inspiration. RS Gold Cheap diablo iii cd key

Garrick Co Ida said...

PHP Training in Chennai
PHP Online Training India