Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exploding by Array of Delimiters

Tags:

Is there any way to explode() using an array of delimiters?

PHP Manual:

array explode ( string $delimiter , string $string [, int $limit ] )

Instead of using string $delimiter is there any way to use array $delimiter without affecting performance too much?

like image 368
JoeC Avatar asked May 18 '10 19:05

JoeC


People also ask

How to explode an array in PHP?

The explode() function breaks a string into an array. Note: The "separator" parameter cannot be an empty string. Note: This function is binary-safe.

How to explode a string PHP?

explode() is a built in function in PHP used to split a string in different strings. The explode() function splits a string based on a string delimiter, i.e. it splits the string wherever the delimiter character occurs. This functions returns an array containing the strings formed by splitting the original string.

What does the explode () function do?

The explode function is utilized to "Split a string into pieces of elements to form an array". The explode function in PHP enables us to break a string into smaller content with a break. This break is known as the delimiter.


1 Answers

$str = 'Monsters are SUPER scary, bro!'; $del = array('a', 'b', 'c');  // In one fell swoop... $arr = explode( $del[0], str_replace($del, $del[0], $str) ); 
like image 151
65Fbef05 Avatar answered Sep 23 '22 21:09

65Fbef05