0
votes

I need to create a CFM page I that will have hyperlinks that are built from data from a database. For example, my database contains a column "Title" and a column "Subject. From "Title" and "Subject" I will create a hyperlink (because all of the pages follow the same scheme: This-is-the-title-this-is-the-subject.html

So the issue is that I need to enter "-" in the spaces. Because right now my CFOUTPUT is just this: This is the title this is the subject.html

Is there a simple way to convert this to This-is-the-title-this-is-the-subject.html?

2
The urlencodedformat() function might be a better approach. However, the replace() function can convert spaces to hyphens. - Dan Bracuk
Is there a compelling SEO reason to have "-" instead of "%20"? - bbuller
@bbuller %20 ? We (at my company) by default, fix this so it doesn't happen either with dashes or underscores orAtLeastByUsingCamelCase.... Not that there is anything wrong with %20 other than it being a barrier for reading words. On second thought if this is how your file names are written then do everything you can to avoid it. Having no spaces in file names will naturally take care of itself on request. - Frank Tudor
Google recommends hyphens instead of %20 - J.T.

2 Answers

11
votes

i think this will solve your problem

 <cfset pageName = "This is the title this is the subject.html" />
 <cfset seoPageName = replace(pageName," ","-","all") /> 
0
votes

I like to use listChangeDelims() for these tasks since you can efficiently add additional chars to change.

seo = listChangeDelims(original, '-', ' ,\' );