KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: URL Encoding and Decoding in 4D
PRODUCT: 4D | VERSION: 13.4 | PLATFORM: Mac & Win
Published On: February 14, 2014

4D does not have a command to do URL Encoding and Decoding. But the PHP Execute command can use "rawurlencode" and "rawurldecode" in methods shown below.

Code snap shot of URL Encoding using PHP "rawurlencode" method:

//Name: rawurlencode
//Description: Takes in a URL string and returns the URL encoded string

C_TEXT($odata;$0;$1)

$result:= PHP Execute("";"rawurlencode";$odata;$1) // URL Encoding

//Put back characters for URL
$odata:= Replace string($odata;"%3b";";") // ; semicolon
$odata:= Replace string($odata;"%2f";"/") // / backslash
$odata:= Replace string($odata;"%3f";"?") // ? question mark
$odata:= Replace string($odata;"%3a";":") // : colon
$odata:= Replace string($odata;"%40";"@") // @ at
$odata:= Replace string($odata;"%26";"&") // & ampersand
$odata:= Replace string($odata;"%3d";"=") // = equal
$odata:= Replace string($odata;"%2b";"+") // + plus sign
$odata:= Replace string($odata;"%2c";",") // , comma
$odata:= Replace string($odata;"%24";"$") // $ dollar sign
$0:= $odata


E.g. $url_encoded:= rawurlencode ("http://www.4d.com.product line")


Code snap shot of URL Decoding using PHP "rawurldecode" method:


//Name: rawurldecode
//Description: Takes in a encoded URL string and returns the decoded URL string

C_TEXT($0;$1)

$result2:= PHP Execute("";"rawurldecode";$0;$1) // URL Decoding


E.g. $url_decoded:= rawurldecode ("http://www.4d.com.product%20line")