Brian Dunning's FileMaker Custom Functions

UrlEncode ( text )

Converts illegal and reserved URL characters into URL-legal hex code.

  Average rating: 3.6 (61 votes) Log in to vote

Jeremiah Small   Jeremiah Small - Show more from this author
Soliant Consulting, Inc.
https://www.soliantconsulting.com

Share on Facebook Share on Twitter

  Sample input:
"http://www.database.com/page.php?field=" & UrlEncode ( "¶ \"!#$%&'()*+,-./:;<=>?@[\\]^`{|}" )
  Sample output:
http://www.database.com/page.php?field=%0D%20%22%21%23%24%25%26%27%28%29%2A%2B%2C%2D%2E%2F%3A%3B%3C%3D%3E%3F%40%5B%5C%5D%5E%60%7B%7C%7D

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

A complete table of hexadecimal codes can be found here http://www.december.com/html/spec/ascii.html

Be aware that curly quotes (single and double) are high-ascii, and will not be converted with this function. If you need quotes, make sure your input is with straight quotes.

 

Comments

Tim Cimbura   Tim Cimbura, LuminFire
May 1, 2010
The following version adds in a few more important substitutions...

/* See http://www.faqs.org/rfcs/rfc2368.html for mailto specifications
The following substitutions and their order are important. mailto: will fail without them.
Reserved characterss in a mailto: URL are "-", "&", and "?"
Must escape the % first, before you start adding them in.
Then do spaces and returns.
Stupify quotes and other stuff
Non-breaking space
Does not handle double quotes or tabs (%09)
Could add substitutions for all diacriticals and other less common characters */

Substitute (text;
["%"; "%25"];
[ " "; "%20"];
["¶"; "%0D"];
[ "!" ; "%21" ] ;
[ "$" ; "%24" ] ;
[ "(" ; "%28" ] ;
[ ")" ; "%29" ] ;
[ "*" ; "%2A" ] ;
[ "+" ; "%2B" ] ;
[ "." ; "%2E" ] ;
[ "=" ; "%3D" ] ;
["\“"; "%22"];
[ "\”"; "%22"];
["‘"; "%27"];
["’"; "%27"];
["'"; "%27"];
["…"; "..."];
["•"; "*"];
[ "-"; "%2D"];
["&"; "%26"];
["="; "%3D"];
["?"; "%3F"];
["#"; "%23"];
[","; "%2C"];
[ "/"; "%2F"];
[":"; "%3A"];
[";"; "%3B"];
[ "<"; "%3C"];
[ ">"; "%3E"];
["@"; "%40&quo
 
Tim Cimbura   Tim Cimbura, LuminFire
May 1, 2010
The above post got truncated. It won't work as displayed here.
 
Alex   Alex
Mar 31, 2011
I added the german "Umlaute" whose are:

[ "A" ; "%C3%84" ] ;
[ "ä" ; "%C3%A4" ] ;
[ "Ö" ; "%C3%96" ] ;
[ "ö" ; "%C3%B6" ] ;
[ " Ü" ; "%C3%9C" ] ;
[ "ü" ; "%C3%BC" ] ;
[ "ß" ; "%c3%9F" ] )

Cheers

Alex
 
Alex   Alex
Mar 31, 2011
Of course it has to be "Ä" instead of "A"
and "Ü".
 
Pacrox   Pacrox, Milano
Sep 16, 2012
Added Extended Character set:

["¢" ; "%A2"] ;
["£" ; "%A3"] ;
["Â¥" ; "%A5"] ;
["|" ; "%A6"] ;
["§" ; "%A7"] ;
["«" ; "%AB"] ;
["¬" ; "%AC"] ;
["¯" ; "%AD"] ;
["º" ; "%B0"] ;
["±" ; "%B1"] ;
["ª" ; "%B2"] ;
["," ; "%B4"] ;
["µ" ; "%B5"] ;
["»" ; "%BB"] ;
["¼" ; "%BC"] ;
["½" ; "%BD"] ;
["¿" ; "%BF"] ;
["À" ; "%C0"] ;
["Á" ; "%C1"] ;
["Â" ; "%C2"] ;
["Ã" ; "%C3"] ;
["Ä" ; "%C4"] ;
["Ã…" ; "%C5"] ;
["Æ" ; "%C6"] ;
["Ç" ; "%C7"] ;
["È" ; "%C8"] ;
["É" ; "%C9"] ;
["Ê" ; "%CA"] ;
["Ë" ; "%CB"] ;
["Ì" ; "%CC"] ;
["Í" ; "%CD"] ;
["ÃŽ" ; "%CE"] ;
["Ï" ; "%CF"] ;
["Ð" ; "%D0"] ;
["Ñ" ; "%D1"] ;
["Ã’" ; "%D2"] ;
["Ó" ; "%D3"] ;
["Ô" ; "%D4"] ;
["Õ" ; "%D5"] ;
["Ö" ; "%D6"] ;
["Ø" ; "%D8"] ;
["Ù" ; "%D9"] ;
["Ú" ; "%DA"] ;
["Û" ; "%DB"] ;
["Ü" ; "%DC"] ;
["Ý
 
Pacrox   Pacrox, Milano
Sep 16, 2012
...cont:

["Ý" ; "%DD"] ;
["Þ" ; "%DE"] ;
["ß" ; "%DF"] ;
["à" ; "%E0"] ;
["á" ; "%E1"] ;
["â" ; "%E2"] ;
["ã" ; "%E3"] ;
["ä" ; "%E4"] ;
["Ã¥" ; "%E5"] ;
["æ" ; "%E6"] ;
["ç" ; "%E7"] ;
["è" ; "%E8"] ;
["é" ; "%E9"] ;
["ê" ; "%EA"] ;
["ë" ; "%EB"] ;
["ì" ; "%EC"] ;
["í" ; "%ED"] ;
["î" ; "%EE"] ;
["ï" ; "%EF"] ;
["ð" ; "%F0"] ;
["ñ" ; "%F1"] ;
["ò" ; "%F2"] ;
["ó" ; "%F3"] ;
["ô" ; "%F4"] ;
["õ" ; "%F5"] ;
["ö" ; "%F6"] ;
["÷" ; "%F7"] ;
["ø" ; "%F8"] ;
["ù" ; "%F9"] ;
["ú" ; "%FA"] ;
["û" ; "%FB"] ;
["ü" ; "%FC"] ;
["ý" ; "%FD"] ;
["þ" ; "%FE"] ;
["ÿ" ; "%FF"] )
 
Oregondean   Oregondean, Oregon, of course!
May 28, 2013
Note that the %25 substitution HAS TO BE FIRST in the list. That was not a casual placement by Brian. If it is further down the list then the "%" signs in the already converted characters will be substituted again and, for example "!" will become %21 then %2521. Learned this the hard way. Thanks Brian!
 
Chris Van Buren   Chris Van Buren, UK
Nov 25, 2014
TIP: There is another custom function for removing smart quotes (http://www.briandunning.com/cf/1115)
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: