SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Decode HTML entities

    Hi all,

    I have data stored in my DB using HTML entities

    for example:

    Code HTML4Strict:
     
    <p> text in here</p>
    is stored as:
    &lt;p&gt;text in here&lt;/p&gt;

    Code ASP:
     
    if I want to decode that using ASP ...how do I do it?
    <&#37;
    Dim page_html
     
    page_html = "&lt;p&gt; text in here &lt;/p&gt;"
     
      Function HTMLDecode(sText)
    	sText = Replace(sText, "&lt;","<" )
    	sText = Replace(sText, "&gt;",">" )
       Next
        HTMLDecode = sText
    	End Function
     
    page_html_decoded = HTMLdecode(page_html)
     
    response.write page_html
    response.write page_html_decoded
     
    %>

    Any help very much appreciated

  2. #2
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just google:

    asp -.net html decode

    many example functions are available

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Yeah, there should be a mate for Server.HTMLEncode but to my knowledge they never got around to it before abandoning ASP Classic. You almost had it with your code block but you had part of a loop messing it up.

    It should look like this and I included an example:
    Code:
    <%
    Function HTMLDecode(sText)
        sText = replace(sText, "&gt;",">")
        sText = replace(sText, "&lt;","<")
        HTMLDecode = sText
    End Function
    
    examplestring = server.HTMLEncode("<p> text in here</p>")
    
    %>
    
    <p>My string encoded looks like this <%= examplestring %></p>
    
    <p>My string unencoded looks like this <%= HTMLDecode(examplestring) %></p>
    Give that a whirl
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  4. #4
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorted but...

    Somethings weird is happening though.

    Why do I need to response.write the original srting (which doesn't write), before the decoded string??


    Code ASP:
     
     
    <%
    Dim page_id
     
    page_id = Request.QueryString("page_id")
     
    page_id = 8
     
      Function HTMLDecode(page_html)
    	page_html = Replace(page_html, "&lt;","<" )
    	page_html = Replace(page_html, "&gt;",">" )
    	page_html = Replace(page_html, "\'","'")
    	page_html = Replace(page_html, "\&quot;","""")
    	page_html = Replace(page_html, "&quot;","""")
      End Function
     
     
     getConn()
    oCmd1.commandtext = "exec wneedham.page_get " & page_id
    oRs1.open oCmd1, , adOpenStatic, adLockReadOnly
     
    while (not oRs1.eof)
        if counter > 0 then response.write "<br>"
     
    	page_title = oRs1("page_title")
    	page_description = oRs1("page_description")
    	page_keywords = oRs1("page_keywords")
    	page_html = oRs1("page_html")
     
    	page_html_decoded = HTMLDecode(page_html) 
     
     oRs1.movenext
    wend
     
     
    %>
     
     
    'Why does it need "response.write page_html" in order to work
    <% response.write page_html  %>
    <% response.write page_html_decoded  %>
    gh:

  5. #5
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,267
    Mentioned
    116 Post(s)
    Tagged
    1 Thread(s)
    Because your function isn't returning a value. Add this line right before the end function

    HTMLDecode = page_html
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  6. #6
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I just learnt something.


Bookmarks

Posting Permissions

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