Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Word count excluding HTML tags

Word count excluding HTML tags

7:40 pm on May 3, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Aug 25, 2003
votes: 0

How would i go about making a word count on a php variable but excluding all content held within (including) HTML tags?



9:41 pm on May 3, 2006 (gmt 0)

New User

10+ Year Member

joined:Sept 29, 2005
votes: 0

I would suggest beginning by 'exploding' the string with something like preg_match. That would allow you to look for something that starts with a less than symbol [ ^< ], plus [ + ] ends with a greater than symbol [ $> ].
7:56 am on May 4, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 7, 2003
votes: 0

regular expression are a really cool thing, but they aren't needed here because of PHP's great set of standard functions:

$count = str_word_count(strip_tags($yourtext));

don't forget to checkout the manual on these 2 ones: