我如何在 PHP 中使用 javascript decodeURI?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7146501/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how can I javascript decodeURI in PHP?
提问by Michael
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 ?
我有一个 javascript,它向 PHP api 发送一些特定信息。在发送之前执行 encodeURI 。如何在 PHP 中“解码”它?我知道 urldecode/urlencode 与 javascript encode/decodeURI 不同,那么我可以使用什么?
回答by symcbean
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.
除非您多次对其进行编码(例如,通过显式调用 encode 方法并将值插入到表单字段中然后提交),否则您不需要做任何事情 - 当请求时它会透明地转换回其原始形式被解析。
回答by 321X
Use encodeURIComponent
in Javascript: http://www.w3schools.com/jsref/jsref_encodeuricomponent.aspand urldecode
in PHP: http://php.net/manual/en/function.urldecode.php
encodeURIComponent
在 Javascript 中使用:http: //www.w3schools.com/jsref/jsref_encodeuricomponent.asp和urldecode
在 PHP 中使用:http: //php.net/manual/en/function.urldecode.php
回答by Adson Diego
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
你可以rawurldecode
在php中使用函数,但是这个函数不是UTF-8,那么你必须utf8_decode
像这样转换成UTF-8
echo utf8_decode(rawurldecode('Educa%C3%A7%C3%A3o%20Multim%C3%ADdia'));