SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    UK
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Convert web address to link ASP

    Hi

    I have a form on my site that allows visitors to post comments, and also weblinks. These comments are then displayed on a comments page.

    Does anyone have a bit of code that will convert 'www.address.com' or 'http://www.address.com' to a clickable link (ie with a href in it) when it is displayed on the web page?

    Many thanks in advance.

    Cheers

    Ray

  2. #2
    SitePoint Addict danfran's Avatar
    Join Date
    Jan 2005
    Location
    New York City
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    only recognizes if HTTP is passed.. but it's a start!

    Dan



    Code:
    function ConstructLink(strString)
    
    	' see if we need to do anything
    	if instr(1,strString,"http://",vbTextCompare) > 0 then
    
    		'make it a link
    		dim newstring, startpos, endpos, URL
    		
    		' find positions of URL
    		startpos = instr(1,strString,"http://",vbTextCompare)
    		endpos = instr(startpos+1,strString," ",vbTextCompare)
    		if endpos = 0 then 
    			endpos = len(strString) 
    			URL = mid(strString,startpos,(endpos-startpos+1))
    			newstring = left(strString,startpos-1)
    			newstring = newstring & "<a target=""_blank"" href=""" & URL & """>" & URL & "</a>"
    			newstring = newstring & right(strString,len(strString)-endpos)
    		else
    			URL = mid(strString,startpos,(endpos-startpos))
    			newstring = left(strString,startpos-1)
    			newstring = newstring & "<a target=""_blank"" href=""" & URL & """>" & URL & "</a>"
    			newstring = newstring & right(strString,len(strString)-endpos+1)
    		end if
    
    		
    		ConstructLink = newstring
    		
    	else
    		' just return the value
    		ConstructLInk = strString
    	end if
    
    end function

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    UK
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Danfran

    That is a good start. Not recognising www. is a bit of an issue though.

    Cheers

    Del


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •