title: PHP count words BETTER than str_word_count
body: <p>Since I read that str_word_count is flawed, I searched for an alternate solution and came across the following, which works quite good in general except of one problem.</p>
  
  <pre><code>function count_words($text) {
  
      //it removes html tags
      $text = preg_replace('/&lt;[^&gt;]*&gt;/', '', $text);
  
      //it removes html space code
      $text = preg_replace(array('/&amp;nbsp;/'), ' ', $text);
  
      //it removes multiple spaces with single
      $text = trim(preg_replace('!\s+!', ' ', $text));
  
      return count(explode(' ', $text));
  }
  </code></pre>
  
  <p>The problem is that it detects a dash "-" as a word.</p>
  
  <p>Example:</p>
  
  <pre><code>This is a title - Additional Info
  </code></pre>
  
  <p>It will count 7 words instead of 6.</p>
  
  <p>Is there a possibility to exclude single characters like - from this word count?</p>