I wrote a post that explain how to count words in a string when you need to ignore the following:
1. Html Code
2. Dividers
3. Extra spaces + new lines
The code is in C# and well documented. Due to the fact that this code is using regular expression it can be used in diffrent languages as well
Link to the post:
Lior.Net » Blog Archive » Count words Using Regular Expression