title: str_replace match only first instance
body: <p>A followup question to <a href="https://stackoverflow.com/questions/3063704/">Get all text between tags with preg_match_all() or better function?</a></p>
  
  <p>Given the following POST data:</p>
  
  <pre><code>2010-June-3
  &lt;remove&gt;2010-June-3&lt;/remove&gt;
  2010-June-15
  2010-June-16
  2010-June-17
  2010-June-3
  2010-June-1
  </code></pre>
  
  <p>I'm wanting to remove ONLY the first instance of 2010-June-3, but the following code removes all the data.</p>
  
  <pre><code>$i = 1;
  $pattern = "/&lt;remove&gt;(.*?)&lt;\/remove&gt;/";
  preg_match_all($pattern, $_POST['exclude'], $matches, PREG_SET_ORDER);
      if (!empty($matches)) { 
          foreach ($matches as $match) {
              // replace first instance of excluded data
              $_POST['exclude'] = str_replace($match[1], "", $_POST['exclude'], $i);  
          }
     }
  
  echo "&lt;br /&gt;&lt;br /&gt;".$_POST['exclude'];
  </code></pre>
  
  <p>This echos:</p>
  
  <pre><code>&lt;remove&gt;&lt;/remove&gt;
  2010-June-15
  2010-June-16
  2010-June-17
  2010-June-1
  </code></pre>
  
  <p>It should echo:</p>
  
  <pre><code>&lt;remove&gt;2010-June-3&lt;/remove&gt;
  2010-June-15
  2010-June-16
  2010-June-17
  2010-June-3
  2010-June-1
  </code></pre>