URLEncode: Difference between revisions
From Pickwiki
Jump to navigationJump to search
mNo edit summary |
Simplified it |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
HomePage>>SourceCode>>BasicSource>>URLEncode | HomePage>>SourceCode>>BasicSource>><nowiki>URLEncode</nowiki> | ||
This is a function to correctly URLEncode a string.<br> | This is a function to correctly URLEncode a string.<br> | ||
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.<br> | |||
References:<br> | |||
See http://www.gbiv.com/protocols/uri/rfc/rfc3986.html#characters<br> | |||
See http://www.permadi.com/tutorial/urlEncoding | |||
<PRE> | <PRE> | ||
function | 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 | |||
</PRE> | |||
</ | HomePage>>SourceCode>>BasicSource>><nowiki>URLEncode</nowiki> |
Latest revision as of 06:44, 6 July 2018
HomePage>>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