PHP explode function will splits the string by string, into array of elements.
Note : This function is binary safe.
This will return the array of strings.
Related articles : strtok(), str_word_count(), implode(), str_split(), chunk_split().
<?php $strExample = explode(" ","Hi from tutorialmine's."); print_r($strExample); ?>
In above example ,We have string “Hi from tutorialmine’s.” Now this function will split the string on the basis of seprator i.e Space letter(blank) and returns the arrays of strings. See below is the output of above code.
If you want to split the string on the basis of separator for e.g. comma ( , ) use below example :
<?php $strExample = "test string 1, test string 2, test string 3, test string 4"; $strOutput = explode(",",$strExample); print_r($strOutput); ?>
Output will be like below:
Below example will show the example of using zero limit, positive limit, negative limits :
<?php $strExample = "test string 1, test string 2, test string 3, test string 4"; // zero limit print_r(explode(',',$strExample,0)); // This will return one single element of an array. echo"<br>"; // positive limit print_r(explode(',',$strExample,2)); // This will return two elements of an array. echo"<br>"; // negative limit print_r(explode(',',$strExample,-1)); // This will return all elements excluding the last element of an array. ?>
Output will be like below:
When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…
In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…
In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…
In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…
When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…
In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…