PHP Split a string by string using explode method

php explode — Split a string by string

Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter.

Example 1

$example  = “example1 example2 example3 example4 example5 example6″;
$result = explode(” “, $example);
echo $result[0]; // example1
echo $result[1]; // example2

This is simple method to explode & trim whitespaces from the exploded elements

$str=”one  ,two  ,       three  ,  four    “;

Array ( [0] => one [1] => two [2] => three [3] => four )

Leave a Reply

Your email address will not be published. Required fields are marked *


Proudly powered by WordPress   Premium Style Theme by