cmeijerink
cmeijerink

Reputation: 21

regex split by %%%%%%[%%%%][%%%%%%%%] and lose the brackets

Like this post I need to split on brackets.

But I also need to lose the brackets..

%%%%%%[%%%%][%%%%%%%%]

into:

array {
[0] -> %%%%%%
[1] -> %%%%
[2] -> %%%%%%%%
}

Upvotes: 2

Views: 112

Answers (2)

FailedDev
FailedDev

Reputation: 26930

This is so easy that you can even get away with match I think :

preg_match_all('/[^[\]]+/', $subject, $result);
$result = $result[0];

$result will have all your matches.

Upvotes: 2

codaddict
codaddict

Reputation: 455000

You can use:

preg_split('/[[\]]+/', $str,-1,PREG_SPLIT_NO_EMPTY)

http://www.ideone.com/S0ijT

Upvotes: 2

Related Questions