friendlyURL(title)
Last updated July 9, 2008
Version: 1 | Requires: ColdFusion MX | Library: UtilityLib
Description:
This function was developed to create SEO friendly urls from article titles (similar to digg and cnn). It removes all non alpha characters and replaces them with a hyphen. It also removes trailing hyphens, apostrophes, etc.
Return Values:
Returns a string.
Example:
This wouldn't be a very SEO friendly URL, would it?
</cfsavecontent>
<cfoutput>
#friendlyUrl(myTitle)#
</cfoutput>
Parameters:
| Name | Description | Required |
|---|---|---|
| title | String to modify. | Yes |
Full UDF Source:
<cfscript>
/**
* UDF that returns an SEO friendly string.
*
* @param title String to modify. (Required)
* @return Returns a string.
* @author Nick Maloney (nmaloney@prolucid.com)
* @version 1, July 9, 2008
*/
function friendlyUrl(title) {
title = replaceNoCase(title,"&","and","all"); //replace &
title = replaceNoCase(title,"&","and","all"); //replace &
title = replaceNoCase(title,"'","","all"); //remove apostrophe
title = reReplaceNoCase(trim(title),"[^a-zA-Z]","-","ALL");
title = reReplaceNoCase(title,"[\-\-]+","-","all");
//Remove trailing dashes
if(right(title,1) eq "-") {
title = left(title,len(title) - 1);
}
return lcase(title);
}
</cfscript>
Search CFLib.org
Latest Additions
Topper added
getCurrentURL
1 hour(s) ago
Daniel Chicayban added
IsListInList
1 day(s) ago
Jeff Howden added
CSVFormat
9 day(s) ago
Tom de Manincor added
flattenStruct
10 day(s) ago
Troy Pullis added
iCalUS
10 day(s) ago