If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > recognizing HTML links

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-18-04, 11:16
-Dman100- -Dman100- is offline
Registered User
 
Join Date: Jan 2004
Posts: 124
recognizing HTML links

I'm using replace to display line breaks, but can't figure out how to display links?

Here is the code:

<%=replace(rsBlogEntry.Fields.Item("blogComment"). Value, VbCrLf, "<br>")%>
or
<%=replace(rsBlogEntry.Fields.Item("blogComment"). Value, char(13), "<br>")%>

Also, what is the difference in using "VbCrLf" and "char(13)"? Is one better than the other or one that is preferred?

I still haven't figured out how to incorporate links? If someone enters
www.somedomainname.com it displays as text. How can I get the link to
display as an actual link?

Thanks.
-Dman10-
Reply With Quote
  #2 (permalink)  
Old 09-20-04, 17:11
aspnuke aspnuke is offline
Registered User
 
Join Date: Sep 2004
Location: San Diego, CA
Posts: 3
MakeHyperlinks

Here's a function that will recognize URLs in your content and convert them into hyperlinks. It will even clean up the link and hide the uninteresting details such as the path and querystring.

Code:
Sub MakeHyperlinks(sContents)
	Dim re, oMatches, oMatch, sURL, sLabel
	
	Set re = New RegExp
	re.Pattern = "(http://|https://|ftp://|gopher://)?([\w+-_]+\.)+(biz|com|gov|edu|name|net|org|us|uk|ca|au|jp)(/[\w-_\.]+)+(\??\S+)"
	re.Global = True
	re.IgnoreCase = True
	re.Multiline = True
	sContents = re.Replace(sContents, "<a href=""$1$2$3$4$5"" target=""_blank"">$2$3</a>")
End Sub
And here is some additional code to test with:

Code:
sContents = "find some info here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsmthreplace.asp if you want"
	MakeHyperlinks sContents
	Response.Write sContents
Reply With Quote
  #3 (permalink)  
Old 09-20-04, 20:47
-Dman100- -Dman100- is offline
Registered User
 
Join Date: Jan 2004
Posts: 124
Thanks for the information. I appreciate the help.

I'm not sure how I would make the call to the function MaKeHyperlinks within this line:



sContents would have to hold the value of the above line wouldn't it?

So, when I create the function would I create a var for sComments?

Something like:<%=replace(rsBlogEntry.Fields.Item("blogComme nt").Value, VbCrLf, "<br>")%>
Sub MakeHyperlinks(sContents)
Dim re, oMatches, oMatch, sURL, sLabel, sContents
sContents = "rsBlogEntry.Fields.Item("blogComment").Value"

Set re = New RegExp
re.Pattern = "(http://|https://|ftp://|gopher://)?([\w+-_]+\.)+(biz|com|gov|edu|name|net|org|us|uk|ca|au|jp) (/[\w-_\.]+)+(\??\S+)"
re.Global = True
re.IgnoreCase = True
re.Multiline = True
sContents = re.Replace(sContents, "<a href=""$1$2$3$4$5"" target=""_blank"">$2$3</a>")
End Sub

Then call the function:
<%=replace(sComments, VbCrLf, "<br>")%>

Would that be correct?
Thanks again,
-Dman100-
Reply With Quote
  #4 (permalink)  
Old 09-20-04, 21:47
aspnuke aspnuke is offline
Registered User
 
Join Date: Sep 2004
Location: San Diego, CA
Posts: 3
Yes, you're on the right track, something like this:

Code:
<html>
<%=FormatComments(rsBlogEntry.Fields.Item("blogComment").Value)%>
</html>
<%
Function FormatComments(sComments)
	sComments = MakeHyperlinks(sComments)
	FormatComments = Replace(sComments, vbCrLf, "<br>")
End Function

Sub MakeHyperlinks(sContents)
	Dim re, oMatches, oMatch, sURL, sLabel, sContents
	sContents = "rsBlogEntry.Fields.Item("blogComment").Value"
	
	Set re = New RegExp
	re.Pattern = "(http://|https://|ftp://|gopher://)?([\w+-_]+\.)+(biz|com|gov|edu|name|net|org|us|uk|ca|au|jp) (/[\w-_\.]+)+(\??\S+)"
	re.Global = True
	re.IgnoreCase = True
	re.Multiline = True
	sContents = re.Replace(sContents, "<a href=""$1$2$3$4$5"" target=""_blank"">$2$3</a>")
End Sub
%>
Reply With Quote
  #5 (permalink)  
Old 09-23-04, 07:50
sgmuse sgmuse is offline
Registered User
 
Join Date: Mar 2004
Location: London, UK
Posts: 71
Thumbs up

EXCELLENT!!!!!!

i've been looking for something like this for AGES!!!

Brilliant, Well Done ASPNUKE!!!, many thanks,
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On