Announcement

Collapse
No announcement yet.

Removing "image" from Text in HTML??

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Removing "image" from Text in HTML??

    I am stumped and need some ideas form those more familiar with html.
    I have a device string generated by a plug-in that has a small picture followed by text. I want to remove the picture and leave the text using VBScript. Is this a simple matter and how? Can I apply it to remove any html and leave text only??
    Thanks for any help,
    BobSpen

    #2
    Bob:

    Do a search for 'StriptHTML'. If you can't find it, I might be able to go through some of my code and send you a snippet.
    Don

    Comment


      #3
      Don,
      Thank you, I will try to find.
      Bob

      Comment


        #4
        See if this helps...

        Stolen from https://gist.github.com/gwobcke/1027133

        PHP Code:

        <%
        FUNCTION 
        stripHTML(strHTML)
          
        Dim objRegExpstrOutputtempStr
          Set objRegExp 
        = New Regexp
          objRegExp
        .IgnoreCase True
          objRegExp
        .Global = True
          objRegExp
        .Pattern "<(.|n)+?>"
          'Replace all HTML tag matches with the empty string
          strOutput = objRegExp.Replace(strHTML, "")
          '
        Replace all < and > with &lt; and &gt;
          
        strOutput Replace(strOutput"<""&lt;")
          
        strOutput Replace(strOutput">""&gt;")
          
        stripHTML strOutput    'Return the value of strOutput
          Set objRegExp = Nothing
        END FUNCTION
        %> 
        Don

        Comment


          #5
          Don,
          This Function does not strip the small icon at the front of the string. How can I easily view the html to see how it is "coded". If I do a copy/paste in Windows to NotePad it seems to strip of the icon and I only see the text string.

          This string I'm working with is an error message that the RFXCOM P/I writes into a device and has the little icon at the beginning-----I am assuming that the string is HTML but maybe it is not????? Do you have the RFXCOM P/I?

          Bob
          Attached Files

          Comment


            #6
            This is just a shot in the dark, but I'm assuming the icon file name is a constant?

            If so, could you use the replace function and strip the name out before you strip the HTML code? Kinda clumsy but I can't see any other way to do it.

            If using Chrome you can right click over the icon to examine the HTML code associated with the statement.

            If you look at the status graphics for that device does that show the image?

            Sorry not to be more helpful.
            Don

            Comment


              #7
              Don is on the right track - this could be a status image (look in the status graphics tab on the device properties page and see whether that icon features anywhere). I am not quite clear on what you are exactly doing either but if you are trying to overwrite that particular device string it might be being reset by the plugin - have you tried writing it to another blank virtual device that does not belong to any plugin?

              Comment


                #8
                Don&Mrhappy,
                Thanks for the ideas. It is not a status icon. It is written by the RFXCOM P/I. I am trying to write it to another virtual device and it is written exactly the same way.
                I did try using Chrome and was able to display the html. It is an image element calling up an image in an RFXCOM directory, so I'm not sure why the "StripHTML" sub did not strip it? I guess I have to figure out how that sub works.
                Bob

                Comment


                  #9
                  Originally posted by BobSpen View Post
                  Don&Mrhappy,
                  Thanks for the ideas. It is not a status icon. It is written by the RFXCOM P/I. I am trying to write it to another virtual device and it is written exactly the same way.
                  I did try using Chrome and was able to display the html. It is an image element calling up an image in an RFXCOM directory, so I'm not sure why the "StripHTML" sub did not strip it? I guess I have to figure out how that sub works.
                  Bob
                  Some regex's (and I do not really understand them at all) can be a little picky. I would I think myself just write the device string to a text file and then look at it, just satisfy myself that the image was not there first. Once you are satisfied that the image is in there and you know that it is fixed then you might be able just to use the Replace function to replace that string of image to nothing.

                  Comment


                    #10
                    I think Adam has the right idea. Can you post the result?
                    Don

                    Comment


                      #11
                      I did get the above to remove HTML(and apparently line breaks also) so I end up with just a long string of text. I kind of wanted keep the <BR></BR> that RFXCOM's P/I added to keep the separation that they thought appropriate; so I made the "pattern" search look for "<img >" and that got rid of the image BUT left the invisible line breaks that I guess Windows inserts----I can't see them so I don't know the pattern to search for. I've looked at the syntax description but I can not figure out what pattern parameter "<>" is looking for but it does seem to strip all but the text!!!

                      FWIW: Her is the script I ended up with(Moving an html device string, that RFXCOM places in there device, to my virtual device while removing html):

                      Sub MoveRfxInputDeviceSensorString()
                      Dim strHTML, Result
                      strHTML=hs.DeviceStringByName("system Input Sensor Display")
                      Result=stripHTML(strHTML)
                      hs.SetDeviceStringByName "system OpenRemoteMessageWindow(X1)-SystemProblem", Result, true
                      End Sub

                      FUNCTION stripHTML(strHTML)
                      Dim objRegExp, strOutput, tempStr
                      Set objRegExp = New Regexp
                      objRegExp.IgnoreCase = True
                      objRegExp.Global = True
                      objRegExp.Pattern = "<(.|n)+?>" 'All Html "< >" tags

                      'Replace all HTML tag matches with the empty string
                      strOutput = objRegExp.Replace(strHTML, "")

                      'Replace all < and > with < and >
                      strOutput = Replace(strOutput, "<", "<")
                      strOutput = Replace(strOutput, ">", ">")
                      stripHTML = strOutput 'Return the value of strOutput
                      Set objRegExp = Nothing
                      'hs.writelog "test", stripHTML
                      END FUNCTION

                      Comment


                        #12
                        So you did get the image name? Can you replace it with a 1 x1 pixel image? Would that serve your purposes?
                        Don

                        Comment


                          #13
                          Don,
                          RegEx replace function replaces "everything" between "<" and ">" or all html tags with ""(empty), so I did not have to search for "img" tags.
                          RegEx is really powerful but somewhat hard to understand the syntax for what to search for.
                          Thanks for your help,
                          Bob

                          Comment

                          Working...
                          X