title: preg_match - text between closing and opening tag
body: <p>I've very odd task to do. </p>
  
  <p>I need to grab text from html tags using preg_match() function in PHP. Problem is that text I need is between closing and opening html tags or this text with tags.</p>
  
  <p>Below is my html string:</p>
  
  <pre><code>&lt;h2&gt;Title of post&lt;/h2&gt; 1 category &lt;strong&gt;task 1&lt;/strong&gt; 1 category &lt;strong&gt;task 2&lt;/strong&gt; 1 category &lt;strong&gt;task 3&lt;/strong&gt;&amp;nbsp; 
  </code></pre>
  
  <p>To be more specific: I need string " 1 category " between <code>&lt;/h2&gt;</code> and <code>&lt;strong&gt;</code> tag.</p>
  
  <p>When i try to grab text between opening and closing tags - It's working fine and I'm using this function:</p>
  
  <pre><code>preg_match_all('#&lt;strong&gt;(.*?)&lt;/strong&gt;#',$string,$matches);
  </code></pre>
  
  <p>I've tried many combinations to get text between closing and opening tags. None of them worked out. I've ended using function like this:</p>
  
  <pre><code>preg_match_all('#&lt;\/strong&gt;(.*?)&lt;strong&gt;#',$content,$matches_all);
  </code></pre>
  
  <p>With no results.</p>
  
  <p>The strange thins is that on online regex testers this function with above pattern with above function works sometimes.</p>
  
  <p>Do I have bad pattern? Am I missing some flags? Do you know what can be best way to get text in this way? Unfortunately I have to do with Regex approach, the solutions like XMLDomParser is not allowed in my case.</p>
  
  <p>Thanks a lot for help.</p>