Forums

ASP

This topic is locked

Displaying or converting Text URLs to Links

Posted 23 Apr 2005 00:55:28
1
has voted
23 Apr 2005 00:55:28 Javier Castro posted:
How would I be able to display text URLs as Links in a display page, using asp. Does anyone know of a bit of code that would recognize links?

Thanks,

Javier

Replies

Replied 23 Apr 2005 14:53:19
23 Apr 2005 14:53:19 Simon Bloodworth replied:
are you calling the values from a database?

Is it just a link value or is the link within other text?

Regards


Simon

DWMX 2004 | ASP | VBScript
Replied 24 Apr 2005 16:09:46
24 Apr 2005 16:09:46 Javier Castro replied:
Thanks Simon for replying.

I have a page with a form where users can write or copy and paste information of events. In case the info they input would have a "www.mysite.com" address within the lines of the text or www.mysite.com, how can I, on the form or at display make it recognize those links. Someone mentioned about selecting the info to be sent as html or text. How would I do that? And yes the info is stored in an Access DB.

Javier
Replied 24 Apr 2005 20:58:32
24 Apr 2005 20:58:32 Rene Bandsma replied:
Can you not solve the problem by using the REPLACE function?

<hr><b>DMXZone support manager</b><br><a href="www.kousman.nl">Kousman web resellers</a>
Replied 25 Apr 2005 14:40:48
25 Apr 2005 14:40:48 Javier Castro replied:
Hi Rene,
I don't know how to do it. Is there a sample of that function that you know of that I can see?
Replied 25 Apr 2005 15:09:13
25 Apr 2005 15:09:13 Rene Bandsma replied:
Just copy 'n paste:

<pre id=code><font face=courier size=2 id=code>
&lt;%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%&gt;
&lt;%

Function InsertHyperlinks(inText)
Dim objRegExp, strBuf
Dim objMatches, objMatch
Dim Value, ReplaceValue, iStart, iEnd

strBuf = ""
iStart = 1
iEnd = 1
Set objRegExp = New RegExp

objRegExp.Pattern = "\b(www|http|\S+@)\S+\b" ' Match URLs and emails
objRegExp.IgnoreCase = True ' Set case insensitivity.
objRegExp.Global = True ' Set global applicability.
Set objMatches = objRegExp.Execute(inText)
For Each objMatch in objMatches
iEnd = objMatch.FirstIndex
strBuf = strBuf & Mid(inText, iStart, iEnd-iStart+1)
If InStr(1, objMatch.Value, "@" Then
strBuf = strBuf & GetHref(objMatch.Value, "EMAIL", "_BLANK"
Else
strBuf = strBuf & GetHref(objMatch.Value, "WEB", "_BLANK"
End If
iStart = iEnd+objMatch.Length+1
Next
strBuf = strBuf & Mid(inText, iStart)
InsertHyperlinks = strBuf
End Function


Function GetHref(url, urlType, Target)
Dim strBuf

strBuf = "&lt;a href="""
If UCase(urlType) = "WEB" Then
If LCase(Left(url, 3)) = "www" Then
strBuf = "&lt;a href=""" & url & """ Target=""" & _
Target & """&gt;" & url & "&lt;/a&gt;"
Else
strBuf = "&lt;a href=""" & url & """ Target=""" & _
Target & """&gt;" & url & "&lt;/a&gt;"
End If
ElseIf UCase(urlType) = "EMAIL" Then
strBuf = "&lt;a href=""mailto:" & url & """ Target=""" & _
Target & """&gt;" & url & "&lt;/a&gt;"
End If

GetHref = strBuf

End Function
%&gt;
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;%
Dim myString
myString = "Go to www.google.com"
%&gt;
This is my string: &lt;%= InsertHyperlinks(myString) %&gt;
&lt;/body&gt;
&lt;/html&gt;
</font id=code></pre id=code>

<hr><b>DMXZone support manager</b><br><a href="www.kousman.nl">Kousman web resellers</a>
Replied 27 Apr 2005 21:10:55
27 Apr 2005 21:10:55 Javier Castro replied:
Thanks for the script Rene. I just got in since the last time I wrote. I'll try it and post if it worked. Cheers.

Javier

Reply to this topic