georgeocrawford
Technical User
OK.
Here's my pattern so far:
What I want to match is all the text between an opening and closing HTML-like tag. I want to allow for nested tags, so the regexp should match up until where the opening tag is properly closed.
Here is a test string:
I am using the following call:
What i need is a regexp which sets $chunks like this:
I am going nuts here. Please could someone put me on the right lines!
______________________
George
Here's my pattern so far:
Code:
$pattern = '/ \< ([[:alnum:]]+) \> ( (?>[^<>]+) | (?R) )* \< \/ \1 \> /Xx';
What I want to match is all the text between an opening and closing HTML-like tag. I want to allow for nested tags, so the regexp should match up until where the opening tag is properly closed.
Here is a test string:
Code:
$string = 'text <replace>comment1<fish>comm<replace>noddy asd</replace>ent2</fish>sdsdsds</replace>text2<gordon>doodle<food>asd</food>qw qwqw</gordon> garn';
I am using the following call:
Code:
$chunks = preg_split($pattern, $string, -1, PREG_SPLIT_DELIM_CAPTURE);
What i need is a regexp which sets $chunks like this:
Code:
Array
(
[0] => text
[1] => replace
[2] => comment1<fish>comm<replace>noddy asd</replace>ent2</fish>sdsdsds
[3] => text2
[4] => gordon
[5] => doodle<food>asd</food>qw qwqw
[6] => garn
)
I am going nuts here. Please could someone put me on the right lines!
______________________
George