URLEncode
From Pickwiki
Jump to navigationJump to searchHomePage>>SourceCode>>BasicSource>>URLEncode
This is a function to correctly URLEncode a string.
URL encoding of a character consists of a "%" symbol, followed by the two-digit hexadecimal representation (case-insensitive) of the ISO-Latin code point for the character.
References:
See http://www.gbiv.com/protocols/uri/rfc/rfc3986.html#characters
See http://www.permadi.com/tutorial/urlEncoding
function urlEncode(param)
equ eSafeChars to 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~'
string = param<1>
flag = param<2> + 0
nstring = ''
max = len(string)
for i = 1 to max
if flag then
*// decode
if string[i,3] match '"%"2X' then
nstring := oconv(string[i+1,2],'my')
i += 2
end else
nstring := string[i,1]
end
end else
*// encode
if index(eSafeChars,string[i,1],1) then
nstring := string[i,1]
end else
nstring := '%':iconv(string[i,1],'my')
end
end
next i
return(nstring)
the:end
HomePage>>SourceCode>>BasicSource>>URLEncode