最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What will decode "email%2540yahoo.com" value in PHP? - Stack Overflow

programmeradmin3浏览0评论

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

Share Improve this question edited Jan 12, 2012 at 8:43 hakre 198k55 gold badges449 silver badges855 bronze badges asked Jan 12, 2012 at 8:39 RyanRyan 14.7k8 gold badges68 silver badges104 bronze badges 2
  • urldecode (x2) – Sjoerd Commented Jan 12, 2012 at 8:41
  • The email is being urlencoded twice – im3r3k Commented Feb 2, 2016 at 20:16
Add a ment  | 

4 Answers 4

Reset to default 5

The 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>);

发布评论

评论列表(0)

  1. 暂无评论