Created
July 7, 2010 22:53
-
-
Save djacobs/467413 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
function createExcerpt(str,maxwords){ | |
if(str) { | |
var excerpt = ''; | |
var words_arr = []; | |
str = str.replace(/^\s+|\s+$/g,""); //trims spaces from start and end of string | |
str = stripTags(str); | |
words_arr=str.split(' '); | |
if(words_arr.length > maxwords) { | |
for (i=0; i < maxwords; i++) { | |
excerpt += words_arr[i] + ' '; | |
} | |
return excerpt + '...'; | |
} else { | |
return str; | |
} | |
} else { | |
return '...'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment