Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

Regex to place all contents of <[edit]><[/edit]> in array

I want everything between

<[edit]>
  and
<[/edit]>

To go into an array.  

This should be case insensitive and must be PHP4 compatible.

So in the below example, the following array should be formed:

-> Item 1
-> Item 2
-> Item 3

<[edit]>Item 1<[/edit]> Hello World <[edit]>Item 2<[/edit]> Testing <[edit]>Item 3<[/edit]> The End
SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hielo, you will want to leave off the U flag, it causes the ungreedy .*? to be greedy .* which is likely not what you intended:
<pre>
<?php
$str = '<[edit]>Item 1<[/edit]> Hello World <[edit]>Item 2<[/edit]> Testing <[edit]>Item 3<[/edit]>';
preg_match_all('#<\[edit\]>(.*?)<\[/edit\]>#i', $str, $matches ) ;
echo print_r($matches[1],true);
?>

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the info!
Thanks for the question and the points.
Avatar of hankknight

ASKER