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
  • 73,160
  • 18
  • 123
  • 143
redcoder
  • 2,115
  • 4
  • 21
  • 23

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,538
  • 4
  • 38
  • 57