Auto-Linking Comments

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

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

 Download FuseGuard WAF for ColdFusion

Trackbacks

Trackback Address: 395/BB0952BD2BAD1FD2492011E7D41C5A13

Comments

On 06/24/2005 at 2:17:05 PM EDT forgetfoo wrote:
1
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

On 06/24/2005 at 2:46:03 PM EDT Pete Freitag wrote:
2
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.

On 06/24/2005 at 3:24:41 PM EDT Pete Freitag wrote:
3
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)

On 10/18/2005 at 5:26:39 PM EDT devon wrote:
4
how do you leave comments on all your friends on your friends list on myspace,any help? email me about it

On 11/05/2005 at 3:06:57 AM EST Anthony wrote:
5
hey, i heard there was an auto comment bot, if anyone knows of this bot please let me know anthony.petini@comcast.net

On 11/15/2005 at 7:52:17 PM EST be dubs wrote:
6
yeah the comment bot what up with it. I know someone has one.

On 11/18/2005 at 2:15:18 PM EST zane wrote:
7
i would love an email also with that auto post bot info as well.

On 01/08/2006 at 6:29:48 PM EST Jim wrote:
8
Just a test... I like http://www.apple.com, and http://www.news.com, and http://www.google.com.

On 02/27/2007 at 8:54:00 PM EST Derrick wrote:
9
Not quite sure I understand this. http://www.cnn.com

On 12/05/2007 at 11:55:30 PM EST kl4e wrote:
10
ok i am trying this out

www.kl4e.com/music

On 03/19/2008 at 10:45:23 AM EDT Jewlz wrote:
11
Hey you guys... Jewlz here... Can you comment my new pics.. please... it will be a huge favor...

thanks

much love, Jewlz

On 10/25/2008 at 3:04:09 PM EDT Test wrote:
12
Humm, I wonder if this works. &#87&#87&#87.example.com

On 11/05/2009 at 4:16:26 PM EST Justin wrote:
13
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.

On 06/05/2010 at 12:15:24 PM EDT christina wrote:
14
I think is better thinking. **************** Christina

On 07/09/2010 at 4:15:41 PM EDT Auto Part Index wrote:
15
This is a wonderful opinion. The things mentioned are unanimous and needs to be appreciated by everyone.

************* Christina

On 09/08/2011 at 8:19:25 AM EDT johnbravo wrote:
16
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?