Here is a script that I use when writing the information
from a database. It determines web and email links
automatically (but it does not allow you to specify text
to use for the link but I am sure you could add that
functionality). The other neat thing is that if the link
is inside of your site, it will open it up in the current
browser. If it is outside of your site then it will open
the link in a new window.
Watch for wrapping in the code.
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", "_self")
Else
IF inStr(objMatch.Value,"yoursite.com") THEN
strBuf = strBuf & GetHref
(objMatch.Value, "WEB", "_self")
ELSE
strBuf = strBuf & GetHref
(objMatch.Value, "WEB", "_blank")
END IF
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
-----Original Message-----
Hi
In my main 'submit news' admin for a site I am doing, I
want to be able tooffer the person submitting the news the ability to
reference other fileswithin their text without the need to use HTML.
My proposal is to use [square brackets] within the text
that will then beparsed when the page is rendered from the database. At
present I have this -e.g.
To download the file [file.exe, click here].
Which I want to render with the words 'click here' as
being a link tofile.exe.
I'm very familiar with instr, replace and split (all of
which I think Iwould need to use) but I cannot figure out how to parse
the above text inthe way I want.
Can anyone offer me some guidance, please? Thanks.
.