Created
March 13, 2013 15:15
-
-
Save ariews/5153098 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { | |
var count = 0; | |
if (htmlData != '') { | |
htmlData = $(htmlData.replace(/[\s\n\t]+/g, ' ')).text(); | |
htmlData = htmlData.replace(/\s+/g, ' ').split(' '); | |
$(htmlData).each(function(index){ | |
if (this != '') count += 1; | |
}); | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment