Web Wiz - Solar Powered Eco Web Hosting

  New Posts New Posts RSS Feed - convert text links to href with image in the text
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

convert text links to href with image in the text

 Post Reply Post Reply
Author
Roberto Randall View Drop Down
Senior Member
Senior Member
Avatar

Joined: 21 August 2009
Location: San Pedro Alc.
Status: Offline
Points: 260
Post Options Post Options   Thanks (0) Thanks(0)   Quote Roberto Randall Quote  Post ReplyReply Direct Link To This Post Topic: convert text links to href with image in the text
    Posted: 26 April 2022 at 8:26pm
I have created a change in the "InsertHyperlinks" function so that when there is an image, the function creates links in the urls and does not modify the source of the image:

Function InsertHyperlinks(ByVal strMessage)

    Dim objRegExp
    Dim objMatches, objMatch
    Dim lngStartPos, lngEndPos
    Dim strURL
    Dim strTempMessage
    Dim strRuteImg1
    Dim strRuteImg2


    'Initilise variables
      strTempMessage = ""
      lngStartPos = 1
      lngEndPos = 1
    strRuteImg1 = "<img src=""http://www."
    strRuteImg2 = "<img src=""https://www."
    
    'Renombramos la ruta de la imagen
    strMessage = Replace(strMessage, strRuteImg1, "[RuteImg1]")
    strMessage = Replace(strMessage, strRuteImg2, "[RuteImg2]")
     
      'Create object
      Set objRegExp = New RegExp

    
    'Match URL's
    objRegExp.Pattern = "((www\.|(http|https|ftp|news|file)+\:\/\/)[&#95;.a-z0-9-]+\.[a-z0-9\/&#95;:@=.+?_,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])"
    objRegExp.IgnoreCase = True     
    objRegExp.Global = True
    
    'Excure regular expression
    Set objMatches = objRegExp.Execute(strMessage)
     
    'loop through each text link found
    For Each objMatch in objMatches
    
           
            'Get end postion
            lngEndPos = objMatch.FirstIndex
           
            'Place in to temp message string
            strTempMessage = strTempMessage & Mid(strMessage, lngStartPos, lngEndPos - lngStartPos + 1)
    
            'Call Href function to build hyperlink
            strTempMessage = strTempMessage & GetHref(objMatch.Value)
    
            'Get the start position
            lngStartPos = lngEndPos + objMatch.Length + 1
      Next
       
      'Replace the text URL in the string with the hyperlink
      strMessage = strTempMessage & Mid(strMessage, lngStartPos)
    
    'Renombramos la ruta de la imagen al estado original
    strMessage = Replace(strMessage, "[RuteImg1]", strRuteImg1)
    strMessage = Replace(strMessage, "[RuteImg2]", strRuteImg2)


      'Retun function
      InsertHyperlinks = strMessage
End Function


On the page that saves the text I have changed it to:

        'If there are no hyperlinks already look to convert text links to hyperlinks
        If InStr(1, strEmailBody, "<a", 1) = 0 AND (InStr(1, strEmailBody, "<img", 1) = 0 OR (InStr(1, strEmailBody, "<img src=""http://www.", 1) > 0 OR InStr(1, strEmailBody, "<img src=""https://www.", 1) > 0)) Then
            strEmailBody = InsertHyperlinks(strEmailBody)
        End If

I add this code to verify that there are no typos in the image url or changes of place or double spaces, etc. If the src of the image is not the same as in the function it does not do it.

This is for the forum programmers in case they are interested and want to adapt them for a new version. If the moderator likes what I've done and wants to delete this post from the forum, I don't care. Because I write it for the forum programmers.

I hope it is understood because I am Spanish and I translate with the Google translator.


https://www.lanocion.es - https://www.lanocion.games - https://www.lanocion.chat
Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9791
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post Posted: 27 April 2022 at 2:11pm
Thank you, will will do some testing and have a look at adding this to Web Wiz Forums.
Back to Top
Roberto Randall View Drop Down
Senior Member
Senior Member
Avatar

Joined: 21 August 2009
Location: San Pedro Alc.
Status: Offline
Points: 260
Post Options Post Options   Thanks (0) Thanks(0)   Quote Roberto Randall Quote  Post ReplyReply Direct Link To This Post Posted: 27 April 2022 at 2:19pm
So far it's going well for me and I haven't had any problems or complaints.
https://www.lanocion.es - https://www.lanocion.games - https://www.lanocion.chat
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.07
Copyright ©2001-2024 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Policy

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2024 Web Wiz Ltd. All rights reserved.