Break the string into an array:
<?php $str = " www.codercto.com " ; print_r ( explode ( " . " , $str ) ) ; ?>The explode() function splits one string into another and returns an array of strings.
Note: The "separator" parameter cannot be an empty string.
Note: This function is binary safe.
explode( separator,string,limit )
parameter | describe |
---|---|
separator | Required. Specifies where to split the string. |
string | Required. The string to split. |
limit | Optional. Specifies the number of array elements to be returned. Possible values: Greater than 0 - returns an array containing at most limit elements Less than 0 - returns an array containing all but the last -limit elements 0 - will be treated as 1, returning an array containing one element |
Return value: | Returns an array of strings. |
---|---|
PHP version: | 4+ |
Update log: | In PHP 4.0.1, the limit parameter is added. In PHP 5.1.0, support for negative limits was added. |
Use the limit parameter to return some array elements:
<?php $str = ' one,two,three,four ' ; // returns an array containing one element print_r ( explode ( ' , ' , $str , 0 ) ) ; print " <br> " ; // array element is 2 print_r ( explode ( ' , ' , $str , 2 ) ) ; print " <br> " ; // Delete the last array element print_r ( explode ( ' , ' , $str ,- 1 ) ) ; ?>