Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

ASP (VBScript) Q.

Options
  • 11-05-2007 3:30pm
    #1
    Moderators, Politics Moderators Posts: 39,822 Mod ✭✭✭✭


    I am trying to do the following and can't figure out how:
    Before a block of text is inserted into a database i want to search it for certain domains (e.g. http://www.boards.ie[...]). Thats easy enough!
    But I then need to get the entire link, encode it and then append it onto another link (so that it will be link1 & encodedLink).
    I then have to do this for any instances of this domain within the text.

    To make matters even more complicated, the domain will probably (but not definitley!) be within HTML so the following characters could be ", >, < or a space (and possibly even more!)

    Is it possible?
    Should I just give up?


Comments

  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    That's more a programming question that specifically an ASP or VBScript question. Do you know the domains in advance ? If you do then it's just a simple search. Loop through the text looking for examples of the domain. Have an array variable holding the number of occurences of each domain. Once the loop is finished loop through the array outputting each link and then perform whatever action you are looking to perform with the generated links.

    If you don't know the domains in advance i.e. if you are looking to examine all possible links in a block of text then you've a much more complicated problem. You'll need to research regular expressions (do a google for "regexp vbscript asp" and you should find a tutorial relevent to the language you are using).

    Hope that was a little help. If I may ask, why do you need to do this?

    -RD


  • Moderators, Politics Moderators Posts: 39,822 Mod ✭✭✭✭Seth Brundle


    Im doing it to create ebay affiliate adverts. Any ordinary ebay link can be encoded and then appended onto a fixed ebay link.
    Cheers! I never thought of that approach!
    I found some code online which I hacked to form the function below:
    <%
    Function EncodeEbayHyperlinks(inText)
    Dim objRegExp, strBuf, ebayAffiliateURL
    Dim objMatches, objMatch
    Dim Value, ReplaceValue, iStart, iEnd
    
      ebayAffiliateURL = "http://affiliate.ebay.ie/whatever/url?"
      strBuf = ""
      iStart = 1
      iEnd = 1
      Set objRegExp = New RegExp
    
      objRegExp.Pattern = "\b(http\://www.ebay\.|http\://cgi\.ebay\.|www.ebay\.|ebay\.|cgi\.ebay\.)\S+\b"
      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)
          strBuf = strBuf & ebayAffiliateURL & Server.UrlEncode(objMatch.Value)
        iStart = iEnd+objMatch.Length+1
      Next
      strBuf = strBuf & Mid(inText, iStart)
      EncodeEbayHyperlinks = strBuf
      Set objRegExp = Nothing
    End Function
    %>
    
    I tested it with several ebay links and so far - so good!
    Thanks Ron


  • Moderators, Politics Moderators Posts: 39,822 Mod ✭✭✭✭Seth Brundle


    Hmmm Friday night @ 11pm & after a hard day at work (coding) and here I am playing with code!
    I need to get a life!


Advertisement