explode
Use one string to split another string into an array
explode()
function breaks the string into an array.
Note: The " separator " parameter cannot be an empty string.
Note: This function is binary safe.
Break strings into arrays:
<?php $str = "Hello world. I love Shanghai!" ; print_r ( exploit ( " " , $str ) ) ; ?>
Try it yourself
Use the limit parameter to return some array elements:
<?php $str = 'one,two,three,four' ; // Zero limit print_r ( exploit ( ',' , $str , 0 ) ) ; // The positive limit print_r ( exploit ( ',' , $str , 2 ) ) ; // Negative limit print_r ( exploit ( ',' , $str , - 1 ) ) ; ?>
Try it yourself
exploit ( separator , string , limit )
parameter | describe |
---|---|
separator | Required. Specifies where to split strings. |
string | Required. The string to be split. |
limit |
Optional. Specifies the number of returned array elements. Possible values:
|