Welcome to WebmasterWorld Guest from 18.104.22.168 , register , free tools , login , search , pro membership , help , library , announcements , recent posts , open posts Become a Pro Member
Word count excluding HTML tags Word count excluding HTML tags PSWorx msg:1292541 7:40 pm on May 3, 2006 (gmt 0) How would i go about making a word count on a php variable but excluding all content held within (including) HTML tags?
feralo msg:1292542 9:41 pm on May 3, 2006 (gmt 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 [ $> ]. hakre msg:1292543 7:56 am on May 4, 2006 (gmt 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:
...] php.net [ ...] php.net