Skip to content

Instantly share code, notes, and snippets.

@ariews
Created March 13, 2013 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ariews/5153072 to your computer and use it in GitHub Desktop.
Save ariews/5153072 to your computer and use it in GitHub Desktop.
/**
* Takes the given HTML data, replaces all its HTML tags with nothing, splits the result by spaces,
* and outputs the array length i.e. number of words.
*
* @param string htmlData HTML Data
* @return int Word Count
*/
function GetWordCount(htmlData) {
return htmlData.replace(/<(?:.|\s)*?>/g, '').split(' ').length;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment