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)

10+ Year Member

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)

10+ Year Member

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)

WebmasterWorld Senior Member 10+ Year Member

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:




Featured Threads

Hot Threads This Week

Hot Threads This Month