My variable with javascript looks like this:
var email = encodeURIComponent($('input[name=\'email\']').val())
email
is clearly being encoded and is producing this when sent to server: email%2540yahoo
What function in PHP will decode this value properly?
I've tried using html_entity_decode
My variable with javascript looks like this:
var email = encodeURIComponent($('input[name=\'email\']').val())
email
is clearly being encoded and is producing this when sent to server: email%2540yahoo.
What function in PHP will decode this value properly?
I've tried using html_entity_decode
- urldecode (x2) – Sjoerd Commented Jan 12, 2012 at 8:41
- The email is being urlencoded twice – im3r3k Commented Feb 2, 2016 at 20:16
4 Answers
Reset to default 5The correct url encoding for @ is %40.
When a url, for example from an e-mail, with the encoded @ character in it, is redirected using a rewrite rule, it will be rewritten as %2540 (the % is encoded as %25). If you keep rewriting / redirecting, you will replace % with %25 each time, ending up with %25252540 (or more 25, you get the picture).
For example clicking this:
http://example?email=info%40example
Will produce after a rewrite and redirect using a rewrite rule:
https://example?info%2540example
in the browser address bar, which does not correctly translate to [email protected] in php.
What function in PHP will decode this value properly?
You don't need to decode anything. $_GET["email"]
and $_POST["email"]
will work just fine. The encodeURIComponent
function is used to properly url encode a url to avoid having invalid urls. If you have a valid url, PHP will successfully be able to read the parameters.
echo urldecode(urldecode('email%2540yahoo.')); // [email protected]
Try urldecode(<value_to_decode_here>);