title: PHP preg_match_all html tags content search
body: <p>I have a problem, i want to do count of symbols in html tags in text.</p>
  
  <p><strong>Text example 1:</strong></p>
  
  <pre><code>Hello &lt;b&gt;world&lt;/b&gt;, &lt;i&gt;stackoverflow&lt;/i&gt;
  </code></pre>
  
  <p><strong>Text example 2:</strong></p>
  
  <pre><code>Hello &lt;b&gt;world, &lt;i&gt;stackoverflow&lt;/i&gt;&lt;/b&gt;
  </code></pre>
  
  <p>So, I need to count how many symbols in <strong>b</strong> and in <strong>i</strong> block separately.</p>
  
  <p>I did this:</p>
  
  <pre><code>preg_match_all('#&lt;(b|i)&gt;(.*)&lt;\/(b)&gt;#Uusi', $temp, $tags_check);
  
  foreach($tags_check[2] as $val)
  {
      if(mb_strlen($val) &gt; 50)
      {
          $errors = 'error';
          break;
      }
  }
  </code></pre>
  
  <p>But it`s works only for first example, in second example i need to do something with regexp. I need to search on start <strong>b</strong> and on end <strong>b</strong>, but not on start <strong>b</strong> and on end <strong>i</strong>, how can i do this?</p>