Get SEO keywords automatically from an article or page
I just finished a nice little function to get the "best" keywords for the page displayed in every website we build with our CMS. Below is an example, what you get is a list of the words that are mostly used in the given page and therefore the best to use as META keywords or tags in your page. At least if you like to be found on the contents of your page...<cfsavecontent variable="txt">
A nice little piece of text with at least twice the word little in the text, and off course three times the word text ;-)
</cfsavecontent>
<cffunction name="getSEOWords" access="public" output="true">
<cfargument name="content" required="true" type="string" />
<cfset var lsStopWords = "stop wordlist in your language (google it)" />
<cfset list = arrayToList(listToArray(REReplace(arguments.content, "[[:space:]]{2,}"," ", "all" ), " ")) />
<cfset var stWords = structNew() />
<cfset var lsTop = "" />
<cfset var aSort = arrayNew(1) />
<!--- Get a unique structure of words counted --->
<cfloop list="#list#" index="value">
<cfif !listFindNoCase(lsStopWords, value) && !isNumeric(value)>
<cfset value = trim(value) />
<cfif structKeyExists(stWords, value)>
<cfset stWords[value] = stWords[value] + 1 />
<cfelse>
<cfset stWords[value] = 1 />
</cfif>
</cfif>
</cfloop>
<!--- Order the structure with words, first keys are the words with the most counts --->
<cfset aSort = structSort(stWords, "numeric", "desc") />
<!--- Get the first 15 words from the list, if the count is more than one. --->
<cfloop from="1" to="15" index="i">
<cfif stWords[aSort[i]] GT 1>
<cfset lsTop = listAppend(lsTop, aSort[i]) />
</cfif>
</cfloop>
<cfreturn lsTop />
</cffunction>
<cfoutput>
#getSEOWords(txt)#
</cfoutput>
3569 viewed | 6 opinion(s) | del.icio.us | Digg it | Tjarko @ 13/10/09 17:19 cet


