title: preg_match_all to find a string that may contain some html tags?
body: <p>My blog articles have a function where a visitor can select part of it and leave a feedback. The feedback's subject is the selection: it can be a few words, or a phrase with some html tags within it (not necessarily around it.)</p>
  
  <p>My function, up until now was the below:</p>
  
  <pre><code>function enco_str_replace_nth( $search, $replace, $subject, $nth = 0 ) {
  
      $found = preg_match_all( '/' . preg_quote( $search ) . '/', $subject, $matches, PREG_OFFSET_CAPTURE );
  
      if (false !== $found &amp;&amp; $found &gt; $nth) {
          return substr_replace( $subject, $replace, $matches[0][$nth][1], strlen( $search ) );
      }
  
      return $subject;
  }
  </code></pre>
  
  <p>It does work when there is no HTML tag(s).</p>
  
  <pre><code>a completely organic product
  </code></pre>
  
  <p>But shows a <strong>Warning: preg_match_all(): Unknown modifier</strong> and doesn't work when there is HTML in it.</p>
  
  <pre><code>MSM is a  &lt;strong&gt;natural nutrient&lt;/strong&gt;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>because &lt;em&gt;it matters&lt;/em&gt; to all of us
  </code></pre>
  
  <p>Any idea of what I should change in this preg_match_all?</p>