Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding links to discussion board messages

Status
Not open for further replies.

calista

Programmer
Jan 24, 2001
545
US
Gee, no sooner do I launch my discussion board, but the users have requested some enhancements. Can you believe that?! ;-)

Seriously, folks, I know it's Friday afternoon, but I didn't want to wait until Monday to post this question. I have been requested to add a feature that will automatically create a clickable link in a message when the user types " or mailto:whoever@whereever.com (just like this board does). Any ideas?

Thanks a lot! Calista,
Jedi Knight
Champion of the Force
 
I don't see a real simple solution but what you can do is just create a loop that uses the find() function to find an occurance of " and then do a find() again to find the next white space. This will give you the location of a link which you can then use the replace() function to replace it with a properly formatted link. Since it's Friday afternoon, I don't have a lot of time for details or to check the code but something like this might work.

<cfset x=1>
<!--- Don't remove the space before http:// in the next line --->
<cfloop condition=&quot;find(msgBody,&quot; gt 0>
<cfset y=&quot;find(msgBody,&quot; &quot;,x)>
<cfset link=mid(msgBody,x,y-x+1)>
<cfset msgBody=replace(msgBody,link,&quot;<a href=&quot;&quot;#link#&quot;&quot;>#link#</a>&quot;)>
<cfset x=find(msgbody,link,y)
</cfloop>

You'll need to add some checks for links that end a sentence as you'll have to strip off the period from the end.

I doubt this will work exactly as is but should be close. I may have the parameters reversed on the find() function but for late in the day Friday, I think it's pretty good :)

Hope it helps,
GJ
 
Just for everyone's FYI, there is a custom tag on Allaire's Developer Exchange called markupURL.cfm that does the job. Why reinvent the wheel, right? Calista :-X
Jedi Knight,
Champion of the Force
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top