URL's being pulled from a database

Results 1 to 3 of 3

Thread: URL's being pulled from a database

  1. #1
    Jason Rivers Guest

    Default URL's being pulled from a database

    Hi, we have an intranet with ASP JAVA and HTML referance/help URL's being pulled from a database. is there a way i can get the ASP to detect if there is a URL in the text and then link the URL?

  2. #2
    Join Date
    Dec 1969

    Default RE: URL's being pulled from a database

    Check out this example<BR><BR>http://www.nvecs.com/makemylink.asp

  3. #3
    Join Date
    Dec 1969

    Default RE: URL's being pulled from a database

    You could try something like the following:<BR><BR>&#039;Set our starting point so it doesn&#039;t bomb<BR>startFrom = 1<BR><BR>&#039;Set up a loop so that it doesn&#039;t just get one URL<BR>&#039;Check to see if there are any URLs first<BR>do while instr(startFrom, yourText, "http://", 1) &#062;= 1<BR> <BR> &#039;Find the starting point of the URL<BR> foundStart = instr(startFrom, yourText, "http://", 1)<BR> <BR> &#039;Find the end point<BR> foundEnd = instr(foundStart, yourText, " ", 1)<BR> <BR> &#039;Use the start and end points to cut out the URL<BR> URL = trim(mid(yourText, foundStart, foundEnd - foundStart))<BR> <BR> &#039;Split up your text so that you can add in the anchor tag<BR> yourTextPrefix = left(yourText, foundStart - 1)<BR> yourTextSuffix = right(yourText, len(yourText) - foundEnd)<BR> <BR> &#039;Insert the anchor tag between the prefix and suffix pieces of text<BR> yourText = yourTextPrefix & "&#060;a href=&#039;" & URL & "&#039;&#062;" & URL & "&#060;/a&#062; " & yourTextSuffix<BR> <BR> &#039;Set our new starting point<BR> &#039;foundStart the original starting point for the current URL<BR> &#039;(len(URL) * 2) - Get the length of the URL times two because it&#039;s in twice now because of the anchor tag<BR> &#039;finally add 16. This is the amount of set characters that aren&#039;t variable(ie. &#060;a href=&#039;&#039;&#062;&#060;/a&#062; )<BR> startFrom = foundStart + (len(URL) * 2) + 16<BR>loop<BR><BR>There is an easier way though, but it depends on how much control you have over the DB. Just make sure that links are put in in the format of something unique, then you just look for the identifiers and set up the link with a replace, oh so simple. The url could be added as such possibly:<BR><BR>[&link]http://somestuff.com[/&link]<BR>[&link]www.cow.com[/&link]<BR><BR>As you can see this allows greater freedom with what can be linked and what can&#039;t, without having to do a whole bunch of extra coding.

Posting Permissions

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