Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Posts
    124

    Unanswered: 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-

  2. #2
    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

  3. #3
    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-

  4. #4
    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
    %>

  5. #5
    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,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •