Thursday, 25 September 2014

explode in PHP

The PHP explode() function is utilized to returns an array formed from a specified string.
The PHP explode() function is easily remembered as "string to array", which simply means that it takes an string and returns an array.

Syntax:

explode (separator,string,limit)
separator : Required. Points out where to break the string.
string : Required. The input string.
limit : Optional. Maximum number of array elements to return.
Note : Separator can not be an empty string and It is binary safe.

Example:

<?php 
$input_str = "Good Morning. It's a Friday today.";
print_r(explode(" ",$input_str));
?>

O/P:

Array (
          [0] => Good
          [1] => Morning.
          [2] => It's 
          [3] => a 
          [4] => Friday 
          [5] => today. 
        )

0 comments:

Post a Comment