fork download
  1. <?php
  2. function rip_tags($string) {
  3.  
  4. // ----- remove HTML TAGs -----
  5. $string = preg_replace ('/<[^>]*>/', ' ', $string);
  6.  
  7. // ----- remove control characters -----
  8. $string = str_replace("\r", '', $string); // --- replace with empty space
  9. $string = str_replace("\n", ' ', $string); // --- replace with space
  10. $string = str_replace("\t", ' ', $string); // --- replace with space
  11.  
  12. // ----- remove multiple spaces -----
  13. $string = trim(preg_replace('/ {2,}/', ' ', $string));
  14.  
  15. return $string;
  16. }
  17. $str = '<p>&nbsp;<p>hello world!</p><p>&nbsp;</p></p>';
  18. $str = trim(html_entity_decode($str));
  19. $str = rip_tags($str);
  20. $c = str_word_count($str);
  21. echo $c;
Success #stdin #stdout 0.02s 24624KB
stdin
Standard input is empty
stdout
2