UnicodeUrlEncode and UnicodeFormUrlEncode (Unicode functions): Difference between revisions
Jump to navigation
Jump to search
m (Created page with "{{Template:Unicode:UnicodeUrlEncode and UnicodeFormUrlEncode subtitle}} <var>UnicodeUrlEncode</var> and <var>UnicodeFormUrlEncode</var> [http://en.wikipedia.org/wiki/Percent-enco...") |
mNo edit summary |
||
Line 14: | Line 14: | ||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul> | ||
<li>If an EBCDIC version of the UTF-8 encoded unicode string is needed, the UTF-8 encoded string should be converted back to unicode using [[Utf8ToUnicode (String function)|Utf8ToUnicode]] and then assigned to a string variable using either implicit Unicode to EBCDIC translation or doing it explicitly with <var>[[UnicodeToEbcdic (Unicode function)|UnicodeToEbcdic]]</var>. The conversion back to EBCDIC should require no [http://en.wikipedia.org/wiki/Character_entity_reference character entity encoding] since URL encoding only uses the most common ASCII characters. | <li>If an EBCDIC version of the UTF-8 encoded unicode string is needed, the UTF-8 encoded string should be converted back to unicode using [[Utf8ToUnicode (String function)|Utf8ToUnicode]] and then assigned to a string variable using either implicit Unicode to EBCDIC translation or doing it explicitly with <var>[[UnicodeToEbcdic (Unicode function)|UnicodeToEbcdic]]</var>. The conversion back to EBCDIC should require no [http://en.wikipedia.org/wiki/Character_entity_reference character entity encoding] since URL encoding only uses the most common ASCII characters. This process is shown in the following [[#Examples|example]]. | ||
<li>The difference between <var>UnicodeFormUrlEncode</var> and <var>UnicodeUrlEncode</var> is that <var>UnicodeFormUrlDecode</var> converts spaces to pluses (<code>+</code>) while <var>UnicodeUrlEncode</var> percent encodes spaces as <code>%20</code>. Typically form URL encoding is only used in HTML form posts when the form is posted using the x-www-form-urlencoded content type. | <li>The difference between <var>UnicodeFormUrlEncode</var> and <var>UnicodeUrlEncode</var> is that <var>UnicodeFormUrlDecode</var> converts spaces to pluses (<code>+</code>) while <var>UnicodeUrlEncode</var> percent encodes spaces as <code>%20</code>. Typically form URL encoding is only used in HTML form posts when the form is posted using the x-www-form-urlencoded content type. | ||
<li>URL encoding is mostly used in web applications or for encoding a URI, possibly in an XML namespace declaration. | <li>URL encoding is mostly used in web applications or for encoding a URI, possibly in an XML namespace declaration. | ||
</ul> | |||
==Examples== | ==Examples== | ||
<ol><li>The following example URL encodes a unicode string and converts it to EBCDIC: | |||
<p class="code">begin | |||
%ebcdic is longstring | |||
%unicode is unicode | |||
= | %unicode = 'I like apple &pi;. and eat it 4 &times; a day.':u | ||
%ebcdic = %unicode:unicodeUrlEncode:utf8ToUnicode | |||
%ebcdic | |||
%unicode | |||
printText {~} = {%ebcdic} | |||
printText {~} = {%ebcdic} | |||
end | end | ||
</p> | </p> | ||
and outputs | and outputs | ||
<p class="output">%ebcdic = I%20like%20apple%20%CF%80.%20and%20eat%20it%204%20%C3%97%20a%20day. | <p class="output">%ebcdic = I%20like%20apple%20%CF%80.%20and%20eat%20it%204%20%C3%97%20a%20day. | ||
</p> | </p></ol> | ||
==See also== | ==See also== | ||
<ul><li>The inverse of <var>UnicodeUrlEncode</var> and <var>UnicodeFormUrlEncode</var> are and <var>[[UrlDecodeUnicode (String function)|UrlDecodeUnicode]]</var> and <var>[[FormUrlDecodeUnicode (String function)|FormUrlDecodeUnicode]]</var>, respectively.</ul> | |||
{{Template:Unicode:UnicodeUrlEncode and UnicodeFormUrlEncode footer}} | {{Template:Unicode:UnicodeUrlEncode and UnicodeFormUrlEncode footer}} |
Revision as of 23:58, 13 March 2011
URL encode unicode characters (Unicode class)
[Introduced in Sirius Mods 7.9]
UnicodeUrlEncode and UnicodeFormUrlEncode URL encode or percent-encode a unicode string.
Syntax
%string = unicode:UnicodeUrlEncode
%string = unicode:UnicodeFormUrlEncode
Syntax terms
%string | The UTF-8 encoded string that results from URL or percent encoding unicode. |
---|---|
unicode | The Unicode method object that is to be URL encoded. |
Usage notes
- If an EBCDIC version of the UTF-8 encoded unicode string is needed, the UTF-8 encoded string should be converted back to unicode using Utf8ToUnicode and then assigned to a string variable using either implicit Unicode to EBCDIC translation or doing it explicitly with UnicodeToEbcdic. The conversion back to EBCDIC should require no character entity encoding since URL encoding only uses the most common ASCII characters. This process is shown in the following example.
- The difference between UnicodeFormUrlEncode and UnicodeUrlEncode is that UnicodeFormUrlDecode converts spaces to pluses (
+
) while UnicodeUrlEncode percent encodes spaces as%20
. Typically form URL encoding is only used in HTML form posts when the form is posted using the x-www-form-urlencoded content type. - URL encoding is mostly used in web applications or for encoding a URI, possibly in an XML namespace declaration.
Examples
- The following example URL encodes a unicode string and converts it to EBCDIC:
begin %ebcdic is longstring %unicode is unicode %unicode = 'I like apple π. and eat it 4 × a day.':u %ebcdic = %unicode:unicodeUrlEncode:utf8ToUnicode printText {~} = {%ebcdic} end
and outputs
%ebcdic = I%20like%20apple%20%CF%80.%20and%20eat%20it%204%20%C3%97%20a%20day.
See also
- The inverse of UnicodeUrlEncode and UnicodeFormUrlEncode are and UrlDecodeUnicode and FormUrlDecodeUnicode, respectively.