Hi, Is there any ASP script that detects a text url in a string and convert it to a clickable link? Like all forums does it. example: http://www.google.com convert it to <a href="http://www.google.com">http://www.google.com</a> thanks in advance
Not that I know of but through the use of INSTR function you could probably cobble something together quickly. Like IF INSTR(somestring,"http://")>0 THEN do something END IF
Never heard of one. The main reason is probably that it would be extremely difficult to determine where the link text ends based on the fact that users often include spaces where they should not. In a forum, links are surrounded by opening and closing URL tags. If you are starting with that, then you can parse for each and add the anchor html to the beginning and end to form the link.
This is a PHP scrip that converts url paths to clickable links $mystring = preg_replace("/(http[s]*:\/\/[\S]+)/", "<a href='\${1}' target='_blank' style='color:#3b5998;'><u>\${1}</u></a>", $string); PHP: Can anybody convert this to ASP?
let me read the link for you then..... Dim MyString as String = Regex.Replace(OriginalString, "(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])", Function(match As Match) String.Format("<a href=""{0}"">{0}</a>", match.ToString())) Code (markup):
The facebook chat does that. Any forum does that. I have the script in PHP but i want the same think in ASP. i have an error message with your script
The code is in VB.Net not VBScript. I am sure a quick google will give you a Classic ASP version but it has been too many years since i last looked at VBScript to remember it.
The greatests web sites are builded in PHP. Anyway. It isn't any script in ASP for converting url paths to links?
OK, i´ll use google for you again. How about: Function parseURL(strText) Set regEx = New RegExp regEx.Global = true regEx.IgnoreCase = True regEx.Pattern = "(\b(ht|f)tp(s?)://[^ ]+\b)" parseURL = regEx.Replace(strText,"<a href=""$1"">$1</a>") End Function Code (markup):
vb.net example: Dim str As String = "Test http://www.google.com abc def http://www.yahoo.com fjksk http://www.google.com <a href='http://www.google.com'>Google</a>" Dim res As String = "" Dim p1 As Integer = 0 Dim p2 As Integer = 1 Dim url As String = "" Do p1 = InStr(p2, str, " http://") If p1 > 0 Then p2 = InStr(p1 + 2, str, " ") If p2 = 0 Then p2 = str.Length url = Mid(str, p1, (p2 - p1)) str = Replace(str, url, " <a href=""" & Trim(url) & """>" & Trim(url) & "</a>") Else Exit Do End If Loop Response.Write(str) Code (markup): classic asp example: Dim str = "Test http://www.google.com abc def http://www.yahoo.com fjksk http://www.google.com <a href='http://www.google.com'>Google</a>" Dim res = "" Dim p1 = 0 Dim p2 = 1 Dim url = "" Do p1 = InStr(p2, str, " http://") If p1 > 0 Then p2 = InStr(p1 + 2, str, " ") If p2 = 0 Then p2 = str.Length url = Mid(str, p1, (p2 - p1)) str = Replace(str, url, " <a href=""" & Trim(url) & """>" & Trim(url) & "</a>") Else [B] Exit Loop[/B] End If Loop Response.Write(str) Code (markup): Most classic asp code will work in asp.net apart from a few minor differences. They main one here being asp.net is "Exit Do" and asp is "Exit Loop". Of course you could just use Do While p1 > 0, but didn't think of that earlier.
Why use all theose lines of code -v- just one line? Dim MyString as String = Regex.Replace(OriginalString, "(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])", Function(match As Match) String.Format("<a href=""{0}"">{0}</a>", match.ToString())) Code (markup):
yes why not ?? first of all add this line to the top using System.Text.RegularExpressions; than one function private string ConvetToLink(string text) { MatchEvaluator me = new MatchEvaluator(ToLink); Regex rx = new Regex(@"\b(ht|f)tp(s?)://\S+"); return rx.Replace(text, me); } private string ToLink(Match m) { return string.Format("<a href=\"{0}\">{0}</a>", m.Value); } Code (markup): ConvetToLink function returns the output as you want... hope this will help you something !!!.. And one more thing ASP.Net is not a language, its one type of environment for creating website.... actually every ASP.net has one language as its back-end like c#, VB.NET so, just tell in which language you want the code... (( if you are not familiar with the ASP.NET than see the first line of any .aspx page and at the top you will see something like <%@ Page Language="C#"... so, in this case my language is c#... check it )) By the way, my above code is in C# and if you want it in VB than use online code converter or other way that you prefer...
I didn't say asp.net was a language. I'm not real good with Regex so I just use string functions. It's simply an alternative solution. And the original question was for an ASP Script that provides a solution for the problem. Also the error messages posted clearly indicate that the solution is required in "VBScript". And so far the only working solutions that I have seen are .Net.