UnicodeUrlEncode and UnicodeFormUrlEncode (Unicode functions): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Template:Unicode:UnicodeUrlEncode and UnicodeFormUrlEncode subtitle}}
{{Template:Unicode:UnicodeUrlEncode and UnicodeFormUrlEncode subtitle}}
<var>UnicodeUrlEncode</var> and <var>UnicodeFormUrlEncode</var> [http://en.wikipedia.org/wiki/Percent-encoding URL encode or percent-encode] a unicode string.
 
<var>UnicodeUrlEncode</var> and <var>UnicodeFormUrlEncode</var> [http://en.wikipedia.org/wiki/Percent-encoding URL encode or percent-encode] a <var>Unicode</var> string.


==Syntax==
==Syntax==
{{Template:Unicode:UnicodeUrlEncode syntax}}
{{Template:Unicode:UnicodeUrlEncode syntax}}
{{Template:Unicode:UnicodeFormUrlEncode syntax}}
{{Template:Unicode:UnicodeFormUrlEncode syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%string</th><td>The [http://en.wikipedia.org/wiki/Utf-8 UTF-8 encoded] string that results from URL or percent encoding <var class="term">unicode</var>.</td></tr>
<tr><th>%string</th><td>The [http://en.wikipedia.org/wiki/Utf-8 UTF-8 encoded] string that results from URL or percent encoding <var class="term">unicode</var>.</td></tr>
<tr><th>unicode</th>
<tr><th>unicode</th>
<td>The <var>Unicode</var> method object that is to be URL encoded.</td></tr>
<td>The <var>Unicode</var> method object that is to be URL encoded.</td></tr>
Line 14: Line 17:
==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.  This process is shown in the following [[#Examples|example]].
<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 <var>[[Utf8ToUnicode (String function)|Utf8ToUnicode]]</var> 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 <code>x-www-form-urlencoded</code> 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>
</ul>


==Examples==
==Examples==
<ol><li>The following example URL encodes a unicode string and converts it to EBCDIC:
The following example URL encodes a <var>Unicode</var> string and converts it to EBCDIC:
<p class="code">begin
<p class="code">begin
   %ebcdic  is longstring
   %ebcdic  is longstring
   %unicode  is unicode
   %unicode  is unicode
   %unicode = 'I like apple &amp;pi;. and eat it 4 &amp;times; a day.':u
   %unicode = 'I like apple &amp;pi;. and eat it 4 &amp;times; a day.':u


   %ebcdic = %unicode:unicodeUrlEncode:utf8ToUnicode
   %ebcdic = %unicode:unicodeUrlEncode:utf8ToUnicode
   printText {~} = {%ebcdic}
   printText {~} = {%ebcdic}
end
end
</p>
</p>
and outputs
The example output is:
<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></ol>
</p>


==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>
<ul>
<li>The inverses of <var>UnicodeUrlEncode</var> and <var>UnicodeFormUrlEncode</var> are <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}}

Latest revision as of 20:40, 6 November 2012

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

%stringThe 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 &pi;. and eat it 4 &times; a day.':u %ebcdic = %unicode:unicodeUrlEncode:utf8ToUnicode printText {~} = {%ebcdic} end

The example output is:

%ebcdic = I%20like%20apple%20%CF%80.%20and%20eat%20it%204%20%C3%97%20a%20day.

See also