Probably not the solution you’re looking for, but because of similar issues I match on a formula field called ‘slug’ rather than on the actual ‘Name’ field. In my case, I use the following formula to slug-ify record names:
LOWER(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE({name},"/","-")," ","-"),"é","e"))
In your case, you might want to do something along these lines:
LOWER(SUBSTITUTE({name}," ","%20"))
There are a number of standard URL-encoding substitutions, but you’re probably safer to include only the ones you need. The following are considered ‘reserved’ characters under RFC 3986 and must be encoded if included as part of a URL:
?!????#????$????&????'????(????)????*????+????,????/
%21??%23??%24??%26??%27??%28??%29??%2A??%2B??%2C??%2F
?:????;????=?????????@????[????]
%3A??%3B??%3D??%3F??%40??%5B??%5D
That said, your web server and/or WordPress will almost certainly intercept ‘/’, ‘?’, and ‘&’, at least, before they get to you. [As you note, the space character should be encoded as ‘%20’ and the percent sign (‘%’) as ‘%25’. If you need to support the latter, it has to be handled in the most deeply nested SUBSTITUTE()
call lest you end up with such things as ‘%2520’ for a space.]
The following formula is overkill, but it will encode all reserved characters except ‘/’, ‘?’, and ‘&’, plus the space character and ‘%’. Again, I recommend you *not* use it but instead create only those substitutions for which you have a definite need.
LOWER(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE({name},"%","%25"),
" ","%20"),
"!","%21"),
"#","%23"),
"$","%24"),
"'","%27"),
"(","%28"),
")","%29"),
"*","%2A"),
"+","%2B"),
",","%2C"),
":","%3A"),
";","%3B"),
"=","%3D"),
"@","%40"),
"[","%5B"),
"]","%5D"))
Maz
-
This reply was modified 7 years, 2 months ago by mazoola.
-
This reply was modified 7 years, 2 months ago by mazoola.
-
This reply was modified 7 years, 2 months ago by mazoola.