Ya know, I coded an ezine not too long ago and had some problems with this very same thing. Supposedly, there's a PHP function for performing this:
str-word-count
But in the version of PHP I was given to use, the function was non-existant. So, I wrote my own jury-rigged solution there, it's the bottom post. If the PHP function doesn't work for you, you might try improving it for yourself. If you have no line breaks, for example, you'll only need to split on spaces don't use the pattern replacing, else you can alter the regex pattern accordingly or just (I missed many punction symbols that I didn't want to be converted to spaces.)