Auto-Linking Comments

June 24, 2005
coldfusion

To avoid comment spam, my blog comments are displayed as plain text. However urls to other entries on my blog are often posted to in the comments. So I wrote a simple regular expression to create hyperlinks out of them:

REReplaceNoCase(comments.comment, 
	"(http://www\.petefreitag\.com/[^[:space:]]+)",
	"<a href=""\1"">\1</a>", 
	"ALL")

If you want this to work with or without the www you can use something like this for the regular expression:

(http://w*\.?petefreitag\.com/[^[:space:]]+)


Related Entries

11 people found this page useful, what do you think?

Comments

now that's pretty damn useful! thx for post it :) [OT] you wouldnt happen to know how they have and can display the content in different languages over at MXNA, would ya? http://weblogs.macromedia.com/mxna/UserPreferences.cfm
Thanks... I think the other languages on MXNA are blogs that are actually written in those languages. I could be mistaken perhaps Christain Cantrell or Mike Chambers will read this and can comment further.
BTW if you find an entry to be useful (or not useful) please use my rating system at the bottom of the post. Then I can construct which posts are most useful, and which are not. See http://www.petefreitag.com/about/ for a list of most useful posts so far. (ooh that should auto-link)
how do you leave comments on all your friends on your friends list on myspace,any help? email me about it
hey, i heard there was an auto comment bot, if anyone knows of this bot please let me know anthony.petini@comcast.net
yeah the comment bot what up with it. I know someone has one.
i would love an email also with that auto post bot info as well.
Just a test... I like http://www.apple.com, and http://www.news.com, and http://www.google.com.
Not quite sure I understand this. http://www.cnn.com
ok i am trying this out www.kl4e.com/music
Hey you guys... Jewlz here... Can you comment my new pics.. please... it will be a huge favor... thanks much love, Jewlz
Humm, I wonder if this works. &#87&#87&#87.example.com
I prefer the following for auto-linking

cfset linkRegEx = "((http|https):\/\/[[:word:]\-_]+(\.[[:word:]\-_]+)+([[:word:]\-\.,@?^=%&amp;:/~\+##]*[[:word:]\-\@?^=%&amp;/~\+##])?)"

cfset thisComment = ReReplaceNoCase(thisComment,linkRegEx,'a href="\1"[Link]&/a','All')

this regEx matched pretty mugh any URL and even ignores bad trailing punctuation.
I think is better thinking.
****************
Christina
This is a wonderful opinion. The things mentioned are unanimous and needs to be appreciated by everyone.

*************
Christina
I think it it the better way.
http://buybacklinks.org.uk

Post a Comment




  



Spell Checker by Foundeo

Recent Entries



foundeo


did you hack my cf?