473,409 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Displaying link text as a hyperlink

Hey,

I don't really know much about ASP but I need some help modifying the way a
field is currently displayed.

Currently the ASP code inside my page is simply:

<%=rs.Fields("Notes")%>

This is fine for displaying the text, but the text contains links which are
currently just being displayed as text. I'd like them to display as
hyperlinks that will open in new windows when clicked upon. so basically I
need some ASP code to detect text starting with http:// or www.etc and
automatically make them into hyperlinks.

Could someone help me out with some code or point me to a webpage.

Thankyou.

Jim
Jul 19 '05 #1
3 1875
<%
'// Example usage:

Dim strText
strText = InsertHyperlinks(rs.fields("This"))
Response.Write strText

'//

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 = "<a href="""
If UCase(urlType) = "WEB" Then
If LCase(Left(url, 3)) = "www" Then
strBuf = "<a href=""http://" & url & """ Target=""" & _
Target & """>" & url & "</a>"
Else
strBuf = "<a href=""" & url & """ Target=""" & _
Target & """>" & url & "</a>"
End If
ElseIf UCase(urlType) = "EMAIL" Then
strBuf = "<a href=""mailto:" & url & """ Target=""" & _
Target & """>" & url & "</a>"
End If

GetHref = strBuf

End Function

%>

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
JimJones <No****@herenospam.com> wrote in message
news:Cup9c.240$54.223@newsfe1-win...
Hey,

I don't really know much about ASP but I need some help modifying the way a field is currently displayed.

Currently the ASP code inside my page is simply:

<%=rs.Fields("Notes")%>

This is fine for displaying the text, but the text contains links which are currently just being displayed as text. I'd like them to display as
hyperlinks that will open in new windows when clicked upon. so basically I need some ASP code to detect text starting with http:// or www.etc and
automatically make them into hyperlinks.

Could someone help me out with some code or point me to a webpage.

Thankyou.

Jim

Jul 19 '05 #2
How would you do it in an normal html page? You'd do:
(Assuming you want the link text to be the url as well)

<a href="http://whatever">http://whatever</a>


So, how would you do it in asp? Substitute <%=variable%> in the places
where the url text would appear in the HTML if you were to manualy write it.

<%
sLink = rs.Fields.Item("Notes").Value
%>

<a href="<%=sLink%>"><%=sLink%></a>
Or use Steve's idea.

Ray at work
"JimJones" <No****@herenospam.com> wrote in message
news:Cup9c.240$54.223@newsfe1-win...
Hey,

I don't really know much about ASP but I need some help modifying the way a field is currently displayed.

Currently the ASP code inside my page is simply:

<%=rs.Fields("Notes")%>

This is fine for displaying the text, but the text contains links which are currently just being displayed as text. I'd like them to display as
hyperlinks that will open in new windows when clicked upon. so basically I need some ASP code to detect text starting with http:// or www.etc and
automatically make them into hyperlinks.

Could someone help me out with some code or point me to a webpage.

Thankyou.

Jim

Jul 19 '05 #3
Thanks for both replies. I have it working now :-)

Jim

"Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
news:ON**************@TK2MSFTNGP11.phx.gbl...
<%
'// Example usage:

Dim strText
strText = InsertHyperlinks(rs.fields("This"))
Response.Write strText

'//

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 = "<a href="""
If UCase(urlType) = "WEB" Then
If LCase(Left(url, 3)) = "www" Then
strBuf = "<a href=""http://" & url & """ Target=""" & _
Target & """>" & url & "</a>"
Else
strBuf = "<a href=""" & url & """ Target=""" & _
Target & """>" & url & "</a>"
End If
ElseIf UCase(urlType) = "EMAIL" Then
strBuf = "<a href=""mailto:" & url & """ Target=""" & _
Target & """>" & url & "</a>"
End If

GetHref = strBuf

End Function

%>

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
JimJones <No****@herenospam.com> wrote in message
news:Cup9c.240$54.223@newsfe1-win...
Hey,

I don't really know much about ASP but I need some help modifying the
way a
field is currently displayed.

Currently the ASP code inside my page is simply:

<%=rs.Fields("Notes")%>

This is fine for displaying the text, but the text contains links which are
currently just being displayed as text. I'd like them to display as
hyperlinks that will open in new windows when clicked upon. so

basically I
need some ASP code to detect text starting with http:// or www.etc and
automatically make them into hyperlinks.

Could someone help me out with some code or point me to a webpage.

Thankyou.

Jim


Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Luis E Valencia | last post by:
I need a link on a datagrid, the link must have fields of the database Like this acciones.aspx?iddireccion=1&idindicador=4 Thanks
4
by: Miguel Dias Moura | last post by:
Hello, I created a datalist in an ASP.Net / VB page. I display the image and price of a few products. When a user clicks an image I want to load the page "detail.aspx?number=id" and send the...
1
by: tshad | last post by:
Is there some reason why the Hyperlink in a DataGrid will not show an image? I have a datagrid with the following: <asp:TemplateColumn visible="false" HeaderText="Skills"> <itemtemplate>...
11
by: Matt | last post by:
Why would this link not work on "Firefox 7.12 Version 1.07"? It works fine in IE? <a href='aac_product_home.asp?Category=product&Section='> <td width="145" <%if lcase(sCategory) =...
4
by: BLob | last post by:
Hi, I need to create an RTF document with PHP. Actually, I am using an already created RTF document which with strings like %var% that I replace with $var before sending the document. I need to...
5
by: kbrad | last post by:
I have an Access database set up with a number of text fields and a hyperlink field which references a different image per record. I am trying write ASP code to retrieve allt his data and images...
4
by: trichert | last post by:
Ok , developing a .aspx page with Visual Web Studio (the full page is at the bottom). Basically its a page that displays all my computers and the current logged on user pulling data from a live...
3
by: William LaMartin | last post by:
I have a gridview (with no properties set) on an aspx page which I populate from an XML file with the code below. The data in the XML file looks like this <description>National Trust for...
0
by: tshad | last post by:
I have set up an upload of doc and pdf files which works fine. If I open up the uploaded files in Word it looks exactly like the my originals. If I open up the files from my web page so that...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.