php - strstr with an ending needle
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-with-php">How to parse and process HTML with PHP?</a><br>
  <a href="http://stackoverflow.com/questions/3969907/php-get-part-of-string-by-searching-for-characters-instead-of-counting-them">PHP - Get part of string by searching for characters, instead of counting them?</a>  </p>
</blockquote>



<p>I have a string:</p>

<pre><code>$str = "hello world, this is mars"
</code></pre>

<p>and I want an improved strstr that will look like this:</p>

<pre><code>istrstr($str, 'world', 'is')
</code></pre>

<p>and the return value will be:</p>

<pre><code>"world, this"
</code></pre>

<p>In other words, there is a needle that starts and a needle that ends.</p>

<p>I was just wondering if there is a solution already, or I should just write one myself...</p>

<p>UPDATE:</p>

<p>based on the answers I did this function:</p>

<pre><code>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);
    }

}
</code></pre>

<p>for now I just need the excluding version, so I didn't bother doing the including one...</p>
