I'm hoping this is easy to achieve, but I'm a bit lost as to how without using a whole bunch of strpos and substr functions. I've seen regex in php, but they only seem to split/match based on one pattern.
Some text ...
"<start>blah blah<end><start>more blah<end>"
I'd like to split the text starting with <start>, ending with <end>, returning an array containing
"blah blah"
"more blah"
Thanks.
Regex Split
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
preg_split('#start_pattern(.*?)end_pattern#',$subject,$limit,PREG_SPLIT_DELIM_CAPTURE);Another way to do it:
Code: Select all
<?php
$myStr = '<start>blah blah<end><start>more blah<end>';
$myStr = str_replace('</end>','',$myStr);
$myArray = explode('<start>',$myStr);
?>