0

I have following two div tags and would like to count only words/character that are human readable.

<div>Pickup</div>
<div>&nbsp;</div>

When I use PHP strlen() , they both return a same value and I cannot use it to show only the Pickup. Same scenario when I use str_word_count().

Any ideas?

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
redcoder
  • 2,233
  • 4
  • 22
  • 24

1 Answers1

0

First decode html entities and remove all html tags:

$text = '<div>Pickup</div>';
echo strip_tags(html_entity_decode($text)); // This show up "Pickup" only

Then count words:

str_word_count($text); // This should return 1
Tony Dinh
  • 6,668
  • 5
  • 39
  • 58