Possible Duplicate:
How to parse and process HTML with PHP?
PHP - Get part of string by searching for characters, instead of counting them?
I have a string:
$str = "hello world, this is mars"
and I want an improved strstr that will look like this:
istrstr($str, 'world', 'is')
and the return value will be:
"world, this"
In other words, there is a needle that starts and a needle that ends.
I was just wondering if there is a solution already, or I should just write one myself...
UPDATE:
based on the answers I did this function:
function istrstr($haystack, $needle_start, $needle_end, $include = false) {
if (!$include) {
$pos_start = strpos($haystack, $needle_start) + strlen($needle_start);
$pos_end = strpos($haystack, $needle_end, $pos_start);
return substr($haystack, $pos_start, $pos_end - $pos_start);
}
}
for now I just need the excluding version, so I didn't bother doing the including one...