Previous Article SELECT Statement, INSERT Statement, UPDATE Statement, DELETE Statement, in ASP using Parameter's, in the combat against SQL & XSS INJECTION |
ASP Classic Linkify - Convert text links into Clickable URLs |
Next Article No Captcha ReCaptcha 2.0 with ASP Classic |
Coding Article #: 53 - Published On: February 07, 2013 @ 00:54:53 AM - Last Updated on: February 07, 2013
This article has been Favorited 15 timesJoin today, and add this to your favorites.
Share With Friends (Updated 6-8-2010)
No Screenshot Available
When creating user interface projects, you want to allow the user to easily add in URLs to other websites. This can be easily done with Linkify in Classic ASP. Just add in the Linkify() around your requested form element, and all the script to do all the work for you.
You must have the link formatted with the http:// at the beginning of it, or the link will not get created.
View Live Example«
The Function
You must provide the http:// before the URL string, in order for it to be processed
An example is in the downloadable files, however, you do not need them.
View Live Example«
You must have the link formatted with the http:// at the beginning of it, or the link will not get created.
View Live Example«
The Function
<%
Function Linkify(Text)
Dim regEx, Match, Matches, patternURLs, patternAnchors, lCount, anchorCount, replacements
patternURLs = "((http|ftp|https)(:\/\/[\w\-_]+)((\.[\w\-_]+)+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)"
patternAnchors = "<a[^>]*?>.*?</a>"
Set replacements=Server.CreateObject("Scripting.Dictionary")
' Create the regular expression.
Set regEx = New RegExp
regEx.Pattern = patternAnchors
regEx.IgnoreCase = True
regEx.Global = True
' Do the search for anchors.
Set Matches = regEx.Execute(Text)
lCount = 0
' Iterate through the existing anchors and replace with a placeholder
For Each Match in Matches
key = "<#" & lCount & "#>"
replacements.Add key, Match.Value
Text = Replace(Text,Cstr(Match.Value),key)
lCount = lCount+1
Next
anchorCount = lCount
' we now search for URls
regEx.Pattern = patternURLs
' create anchors from URLs
Text = regEx.Replace(Text, "<a href=""$1"">$1</a>")
' put back the originally existing anchors
For lCount = 0 To anchorCount-1
key = "<#" & lCount & "#>"
Text = Replace(Text,key, replacements.Item(key))
Next
Linkify = Text
End Function
%>
You must provide the http:// before the URL string, in order for it to be processed
An example is in the downloadable files, however, you do not need them.
<%=Linkify(request.Form("MyText1"))%>
View Live Example«
Post to Facebook about: ASP Classic Linkify - Convert text links into Clickable URLs