On the server side the PHP code will be using urldecode()
function to decode, but the JavaScript code is responsible to encode the URL. Which of the following JavaScript function is compatible with the PHP urldecode()
function:
- escape()
- encodeURI()
- encodeURIComponent()
You can use either encodeURI
or encodeURIComponent
. The php manual states:
Decodes any %## encoding in the given string.
So whatever the encoding function encodes, all %##
sequences are decoded. So you can use either one of the JavaScript functions to encode it.
(In kind-of response to Gumbo's answer, which he removed?)
php's urldecode
also decodes +
signs to spaces (because it implements a different standard). To make sure that no plus signs that are actually intended are decoded on the php side, just use encodeURIComponent
to be sure. That encodes +
to %2B
, which is then again safe from php's urldecode
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With