View Full Version : Opposite Server.HTMLEncode
isleshocky77
07-26-2002, 06:28 PM
How can I reverse Server.HTMLEncode
whammy
07-26-2002, 11:34 PM
You shouldn't need to - make sure you're only using Server.HTMLEncode around a variable ONLY when you write to the page and it's needed, not when you are writing to a database.
Or you could use:
function decode(myStr)
dim k,s1,s2
'while there is stuff left to replace
while inStr(myStr,"&#")
k = inStr(myStr,"&#")'index of the "&#" inside string
s1= Mid(myStr,k,6) 'let's get the whole shebang (#&xxx;)
s2= Mid(s1,3,3) 'let's get only the ascii code (xxx)
'replace the (#&xxx;) with the proper char
myStr = replace(myStr,s1,chr(s2))
wend
decode=myStr
end function
--or--
<%''bit more updated
Private Function HTMLDecode(byVal encodedstring)
Dim tmp, i
tmp = encodedstring
tmp = Replace( tmp, """, chr(34) )
tmp = Replace( tmp, "<" , chr(60) )
tmp = Replace( tmp, ">" , chr(62) )
tmp = Replace( tmp, "&" , chr(38) )
tmp = Replace( tmp, " ", chr(32) )
For i = 1 to 255
tmp = Replace( tmp, "&#" & i & ";", chr( i ) )
Next
HTMLDecode = tmp
End Function
%>
And of course, there always is
string = HTMLDecode(encodedstring)
whammy
07-26-2002, 11:47 PM
Good functions! :)
gorilla1
03-14-2003, 06:52 PM
Is there an answer to this question?
Is there a question ?
The only issue is understanding why you should use serve.HTMLEncode; to prevent lads like me to insert javascript and stuff into your textfields, and to wrack all clients machines when you write the values of that textfield to there browser (--> to make sure the values are showd as text and are not run as code) + to ensure that they are display as inserted in the db.
(should only be used on textfields)
why reverse it? The values are treated when parsed and immedeately sent to the browser. Even if you would save thes values again, they don't need to be encoded or whatever again.
whammy
03-14-2003, 11:39 PM
raf is absolutely right - Server.HTMLEncode() should never have to be "decoded".
If you're using it on variables when you request them, you're not using it for what it's intended for. ;)
A little experimentation should clear that up - you might also want to look at this:
http://www.solidscripts.com/email.txt
That'll give you a sense of where to use it... :)
gorilla1
03-15-2003, 03:59 AM
Strange - when I looked at this thread earlier today, I could swear only the 2 first posts were there - which is why I revived it - the origianl question appeared unanswered. But apparently I simply thought I saw the end of the thread when I did not. Good thing my new monitor arrived tonight...
There are some nice answers there. The htmlDecode on the server I am working with comes back as unsupported object or some such. So that is not an option.
As far as why one might need this, I think maybe the saying 'never say never' applies. I am using a feed from another site. The data is html encoded. I then need to store the data as an asp program which i execute elsewhere. The html encoding means that the beginning <? shows as < (and similar characters are included which asp does not handle)which trips up the later attempt to execute the code...
G
if you take in code from another app, just ask them not to encode it. HTML encode is for code that targets a browser.
So it doesn't make sense. It should only be code that's used browsersided, and not serversided like an asp :confused:
so i'd contact the party that sends you the code.
if they inded to supplie this code like you discribe, it'll probably be best to wrap some XML code around it. (Just two tags like <raf> the untreated code </raf>)
you could then remove these tags (or query on them) and have the code you need. XML is the (only?) way to go if you want to distibute data or code between app's
else: do some replacing (see Feyds post) but don't know if that will cover everything
gorilla1
03-15-2003, 02:44 PM
raf (and everyone),
Thanks for the help!
G
arthurdaley
07-07-2005, 07:27 PM
I added the following to make it decode incoing mail messages with %2D type encoding:
Private Function HTMLDecode(byVal encodedstring)
Dim tmp, i
tmp = encodedstring
tmp = Replace( tmp, """, chr(34) )
tmp = Replace( tmp, "<" , chr(60) )
tmp = Replace( tmp, ">" , chr(62) )
tmp = Replace( tmp, "&" , chr(38) )
tmp = Replace( tmp, " ", chr(32) )
For i = 1 to 255
tmp = Replace( tmp, "&#" & i & ";", chr( i ) )
Next
For i = 40 to 255
tmp = Replace( tmp, "%" & Hex(i), chr( i ))
Next
HTMLDecode = tmp
End Function
I use this to decode data I receive back from my payment processor. I disagree that this code is unneccessary.
I think there might be a conflict after the expansion of %25 (%), if a string that looks like hex 40-255, but I'll leave that for someone else to play with
ArthurDaley :cool:
isleshocky77
07-07-2005, 07:48 PM
Wow,
Talk about reviving an old question. I got an email about this topic and couldn't remember when, why, or for what I was subscribed to this thread. Not to mention I apparently started.. 3 years ago. Well thanks for the replies, I wish I could say it came in handy, but I don't remember.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.