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[2] ; // Display: go
echo $array[3] ; // Display: to
echo $array[4] ; // Display: USA
echo $array[0] ; // Display: I
echo $array[1] ; // Display: willecho $array[2] ; // Display: go
echo $array[3] ; // Display: to
echo $array[4] ; // Display: USA
?>
This function returns an array of small strings.
You can also explode the string to many string, rather than an array.
<?php
echo $string2 ; // Display: 145
echo $string3 ; // Display: 165
echo $string4 ; // Display: 175
?>
$string = '125:145:165:175' ;
list($string1 , $string2 , $string3 , $string4 ) = explode ( ':' , $string ) ; // This will explode
echo $string1 ; // Display: 125echo $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.