tags:

views:

60

answers:

1

Sorry for unclear description, my English is not good.

My problem is that I want to decode a string, and this string has nested content delimited by {}.
For example:

The string:

{any string0{any string 00{any string 000....}}}{any string1}any string.

The result I want to get:

 array[0] = {any string0{any string 00{any string 000....}}}
 array[1] = {any string1}

I hope it's clear enough.

+4  A: 

Making the best use of the (oddly put, and hopefully soon-to-be-edited) question, the following takes your example string and provides your example array.

$subject = '{blah\blah{\blah\blah...{\bl....}}}{blah...}blah... ';
$pattern = '/\{(?>[^{}]++|(?R))*\}/';

preg_match_all($pattern, $subject, $matches);
print_r($matches[0]);

Which produces:

Array
(
    [0] => {blah\blah{\blah\blah...{\bl....}}}
    [1] => {blah...}
)
salathe
It works, you saved my day, thanks so much.
kelly
You're welcome I guess. :-)
salathe
MY EYES! IT HURTS!
M28