URLEncode: Difference between revisions
From Pickwiki
Jump to navigationJump to search
mNo edit summary |
Simplified it |
||
| Line 3: | Line 3: | ||
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> | 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> | References:<br> | ||
| Line 11: | Line 10: | ||
<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') | |||
if index( | |||
end | end | ||
end | |||
next i | next i | ||
return( | return(nstring) | ||
the:end | the:end | ||
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