Results 1 to 11 of 11

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

  1. #1
    PowerPoster
    Join Date
    Jan 08
    Posts
    6,752

    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?
    The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved


    When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day

  2. #2
    Member
    Join Date
    Dec 10
    Posts
    57

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


  3. #3
    Member
    Join Date
    Dec 10
    Posts
    57

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


  4. #4
    PowerPoster
    Join Date
    Jan 08
    Posts
    6,752

    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
    The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved


    When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day

  5. #5
    PowerPoster
    Join Date
    Jan 08
    Posts
    6,752

    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
    The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved


    When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day

  6. #6
    PowerPoster
    Join Date
    Jan 08
    Posts
    6,752

    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, !
    The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved


    When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day

  7. #7
    Frenzied Member Bonnie West's Avatar
    Join Date
    Jun 12
    Location
    InIDE
    Posts
    1,574

    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
    PowerPoster
    Join Date
    Jan 08
    Posts
    6,752

    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.
    The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved


    When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,636

    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 subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * 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??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

  10. #10
    PowerPoster
    Join Date
    Jan 08
    Posts
    6,752

    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.
    The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved


    When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 02
    Location
    Bristol, UK
    Posts
    35,548

    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
  •