I have a javascript which sends some specific information to a PHP api . Before to send it performs encodeURI . How can I "decode" it in PHP ? I understand that urldecode/urlencode is different that javascript encode/decodeURI so what can I use ?
Asked
Active
Viewed 1.7k times
5
-
1If the PHP is not getting the information via querystring don't use `encodeURI`, simple as that. :-) – Shadow The GPT Wizard Aug 22 '11 at 11:06
-
would using the javascript escape() and unescape() function work for you? – user746379 Aug 22 '11 at 11:04
3 Answers
6
Use encodeURIComponent
in Javascript: http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp and urldecode
in PHP: http://php.net/manual/en/function.urldecode.php

321X
- 3,153
- 2
- 30
- 42
-
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent – Mindeater Jul 07 '18 at 13:31
6
Unless you've encoded it multiple times (e.g. by explicitly calling the encode method AND inserting the value into a form field which is then submitted) you don't need to do anything - it is transparently converted back to its original form when the request is parsed.

symcbean
- 47,736
- 6
- 59
- 94
3
You can use rawurldecode
function in php, but this function is not UTF-8, then your have to convert to UTF-8 with utf8_decode
like this
echo utf8_decode(rawurldecode('Educa%C3%A7%C3%A3o%20Multim%C3%ADdia'));

Jago
- 2,751
- 4
- 27
- 41

Adson Diego
- 61
- 2