homepage Welcome to WebmasterWorld Guest from 54.197.94.241
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
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?

TIA

vistaworx

 

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...]

--hakre

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved