Livecode Wiki
Advertisement

Returns a string that has been transformed so that it can be posted to an HTTP server as a URL.

Syntax:

URLEncode(<formString>)

Examples:

URLEncode("ABC123") -- returns "ABC123"
URLEncode("Test string $$") -- returns "Test+string+%24%24"
put URLEncode("http://www.example.net/document.html") into newURL

Use the URLEncode function to encode a URL so it can be safely posted to an HTTP server.

Letters and numbers (alphanumeric characters) are not transformed by the URLEncode function. The representation used for non-alphanumeric characters is a percent sign followed by two hexadecimal digits. For example, the ASCII value of the character "~" is 126; the hexadecimal equivalent of 126 is 7E. So wherever the character ~ appears in the formString, it is converted to "%7E".

Anytime you have problem of encoding with transferring data, this function used in conjunction with URLDecode may save a lot of work.

However it uses the last standard of URL, where space is converted to the plus sign:

"Hello world" = "Hello+world"

this could not work with some software. So you need to replace "+" with "%20", like with this function:

function urlencode2 temptext
  put urlencode(temptext) into temptext
  replace "+" with "%20" in temptext
  return temptext
end urlencode2

Please note that tis function works only with UTF8 chars or chars that have the same value in UTF8, so if your computer doesn't use UTF8, use TextEncode and TextDecode like these examples:

put urlencode("Müller")
=
M%FCller
put urlencode(textEncode("Димитрий","UTF8"))
=
%D0%94%D0%B8%D0%BC%D0%B8%D1%82%D1%80%D0%B8%D0%B9
put urldecode("M%FCller")
=
Müller
put textdecode(urldecode("%D0%94%D0%B8%D0%BC%D0%B8%D1%82%D1%80%D0%B8%D0%B9"),"UTF8")
=
Димитрий

Parameters:

  • formString (string):
  • Returns:The URLEncode function returns the formString, with spaces converted to "+" and characters other than letters and numbers converted to their hexadecimal escape representation.

See also: URLDecode, TextEncode

Advertisement