什么将解码“;电子邮件%2540yahoo.com“;值

What will decode "email%2540yahoo.com" value in PHP?

本文关键字:com %2540yahoo 电子邮件 什么 解码      更新时间:2023-09-26

我的javascript变量如下所示:

var email = encodeURIComponent($('input[name=''email'']').val())

email被清楚地编码,并在发送到服务器时产生:email%2540yahoo.com

PHP中的哪个函数将正确解码此值?

我尝试过使用html_entity_decode

@的正确url编码是%40。

当使用重写规则重定向url(例如来自电子邮件的url,其中包含编码的@字符)时,它将被重写为%2540(%编码为%25)。如果你继续重写/重定向,你每次都会用%25替换%,最终得到%2525540(或者更多的25,你会得到图片)。

例如,点击此:

http://example.org?email=info%40example.org

将在重写后生成并使用重写规则重定向:

https://example.org?info%2540example.org

在浏览器地址栏中,无法正确转换为info@example.org在php中。

PHP中的哪个函数将正确解码此值?

你不需要解码任何东西。CCD_ 4和CCD_。encodeURIComponent函数用于正确地对url进行url编码,以避免出现无效的url。如果你有一个有效的url,PHP将能够成功地读取参数。

echo urldecode(urldecode('email%2540yahoo.com')); // email@yahoo.com

尝试urldecode(<value_to_decode_here>);