Url til link funktion?
Hej Alle,jeg har lavet understående eksempel, som jeg håber en RG haj lige vil hjælpe mig med :)
Jeg har sat understående eksempel op, det eneste jeg mangler i funktionen er at lave www.domain.com til et link også :)
Understående er eksemplet, dernæst resultatet den skriver ud:
Code
---------------------------------------------
<%
Function CreateLinks(strText)
'-- Declare object
Dim objReg
Set objReg = New RegExp
'-- Set rules
objReg.Global = True
objReg.IgnoreCase = True
'-- Test for ordinary hyperlinks
objReg.Pattern = "(\S+\:\/\/{1}\S+\b)"
strText = objReg.Replace(strText, "<a href=""$1"">$1</a>")
'-- Test for e-mails
objReg.Pattern = "(\S+@{1}\S+\.[a-z][a-z]+\b)"
strText = objReg.Replace(strText, "<a href=""mailto:$1"">$1</a>")
'-- Clear object, return convert
Set objReg = Nothing
CreateLinks = strText
End Function
'-- Test streng
string_test = string_test & "#1: www.domain.com" & ", "
string_test = string_test & "#2: http://www.domain.com" & ", "
string_test = string_test & "#3: http://domain.com" & ", "
string_test = string_test & "#4: www.domain.com/extra/path/" & ", "
string_test = string_test & "#5: www.domain.com/extra" & ", "
string_test = string_test & "#6: http://search.domain.com" & ", "
string_test = string_test & "#7: http://search.domain.com/?site=1&site=2&site=3&site=4&test"
string_test = CreateLinks(string_test)
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="imagetoolbar" content="no" />
</head>
<body>
<pre>
<%=string_test%>
</pre>
</body>
</html>
Output
---------------------------------------------
#1: www.domain.com,
#2: <a href="http://www.domain.com">http://www.domain.com</a>,
#3: <a href="http://domain.com">http://domain.com</a>,
#4: www.domain.com/extra/path/,
#5: www.domain.com/extra,
#6: <a href="http://search.domain.com">http://search.domain.com</a>,
#7: <a href="http://search.domain.com/?site=1&site=2&site=3&site=4&test">http://search.domain.com/?site=1&site=2&site=3&site=4&test</a>
Er der en venlig sjæl der lige kan se løsningen ?