Possible Duplicate:
Get content between two strings PHP
I am trying to create a php function that will return an array of all occurrences of text between two substrings. I am useless at regular expression and would find this very handy, I'm sure there is already a very nice one out there but I can't find it.
function getAllBetweenStr($input, $start, $end)
{
//DO STUFF
//RETURN ARRAY
}
$inputStr ="<a href='http://formaco4/en/abc' class='currentLink' hreflang='en'>abc1/a>
<a href='http://formaco4/en/abc/b1' hreflang='en'>abc2</a>
<a href='http://formaco4/en/abc/b2' hreflang='en'>abc3</a>
<a href='http://formaco4/en/abc/b3' hreflang='en'>abc4</a>";
$linkStr = array();
$linkStr = getAllBetweenStr($inputStr, "http://formaco4/en/'", "' hreflang")
The return array would be like this Array([0] => "abc/b1", [1] => "abc/b2", ... , [n] => "gingers/rule")
I have this function already if it helps:
function getBetweenStr($string, $start, $end)
{
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}