Current Location: Home> Function Categories> explode

explode

Use one string to split another string into an array
Name:explode
Category:String
Programming Language:php
One-line Description:Break the string into an array.

Definition and usage

explode() function breaks the string into an array.

Note: The " separator " parameter cannot be an empty string.

Note: This function is binary safe.

Example

Example 1

Break strings into arrays:

 <?php
$str = "Hello world. I love Shanghai!" ;
print_r ( exploit ( " " , $str ) ) ;
?>

Try it yourself

Example 2

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

grammar

 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:

  • Greater than 0 - Returns an array containing up to limit elements
  • Less than 0 - Returns an array containing all elements except the last - limit elements
  • 0 - Return an array containing an element
Similar Functions
Popular Articles