How To Do: Translate HTML codes to normal text-VBForums
Results 1 to 11 of 11

Thread: How To Do: Translate HTML codes to normal text

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    9,151

    How To Do: Translate HTML codes to normal text

    I have a script program that I tried using the following code:

    Code:
      '
      '
      $value =~ tr/+/ /;
      $value =~ tr/%21/!/;
      $value =~ tr/%22/"/;
      $value =~ tr/%25/%/;
      $value =~ tr/%26/&/;
      $value =~ tr/%28/(/;
      $value =~ tr/%29/)/;
      $value =~ tr/%2C/,/;
      $value =~ tr/%2F/|/;
      $value =~ tr/%3C/>/;
      $value =~ tr/%3D/=/;
      $value =~ tr/%3E/</;
      '
      '
    Unfortunately it does'nt do what I though it would do.

    I want to take each HTML code like %xx and change it to the real character.

    For example %3E = "<" and %3C = ">"

    Anyone know how to do this?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    Lively Member
    Join Date
    Dec 2010
    Location
    http://bbat.forumeiro.com/
    Posts
    80

    Lightbulb Re: How To Do: Translate HTML codes to normal text


  3. #3
    Lively Member
    Join Date
    Dec 2010
    Location
    http://bbat.forumeiro.com/
    Posts
    80

    Lightbulb Re: How To Do: Translate HTML codes to normal text


  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    9,151

    Re: How To Do: Translate HTML codes to normal text

    Quote Originally Posted by Hackoo View Post
    That would OK but my code is not VBScript


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    9,151

    Re: How To Do: Translate HTML codes to normal text

    Quote Originally Posted by Hackoo View Post
    Well, don't know about this one. It doesn't really give me the script code I need


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    9,151

    Re: How To Do: Translate HTML codes to normal text

    The code I posted translates a one for one character.

    For example

    This code line takes all occurances of plus (+) sign and changes them to blank or spaces
    $value =~ tr/+/ /;

    What this will do is change all % to !, then all 2 to ! then all 1 to ! so I wind up with !!!
    $value =~ tr/%21/!/;

    but that is not what I need. I need %21 to be changed to only one character, !


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  7. #7
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    3,157

    Re: How To Do: Translate HTML codes to normal text

    Here, try this:

    Code:
    Private Declare Function UrlUnescapeW Lib "shlwapi.dll" (ByVal pszURL As Long, ByVal pszUnescaped As Long, ByRef pcchUnescaped As Long, ByVal dwFlags As Long) As Long
    
    Public Function URLDecode(ByRef sURL As String) As String
        Const INTERNET_MAX_URL_LENGTH = 2083&, E_POINTER = &H80004003
        Dim ChrCnt As Long
    
        ChrCnt = INTERNET_MAX_URL_LENGTH + 1&
        Do:  URLDecode = Space$(ChrCnt - 1&)
        Loop While UrlUnescapeW(StrPtr(sURL), StrPtr(URLDecode), ChrCnt, 0&) = E_POINTER
        If ChrCnt < Len(URLDecode) Then URLDecode = Left$(URLDecode, ChrCnt)
    
        ChrCnt = InStr(URLDecode, "+")
        While ChrCnt
            Mid$(URLDecode, ChrCnt) = " "
            ChrCnt = InStr(ChrCnt, URLDecode, "+")
        Wend
    End Function

    Note:

    MSDN says "input strings cannot be longer than INTERNET_MAX_URL_LENGTH".
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    9,151

    Re: How To Do: Translate HTML codes to normal text

    This has nothing to do with Microsoft, or Windows. This is a script program that runs on the web server. It's a Perl script program.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  9. #9
    PowerPoster
    Join Date
    May 2002
    Posts
    25,472

    Re: How To Do: Translate HTML codes to normal text

    Then it should have been posted in the correct forum...
    like the XML, HTML, Javascript, Web and CSS one... it even specifies that "Topics include: Perl, Cold Fusion, etc. (Java, ASP & VB Script and PHP are separate)"

    I'll ask a mod to move it....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    9,151

    Re: How To Do: Translate HTML codes to normal text

    I didn't see the other forum. I posted here because I read this:

    This forum is the place to post all your questions about using the Internet within your applications. Topics include: writing components for ASP (classic), VB Script, and more.

    Guess I didn't look far enough.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,192

    Re: How To Do: Translate HTML codes to normal text

    Thread moved

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.