将 URLDecoder.decode(temp, “UTF-8”) 转换为 php


convert URLDecoder.decode(temp, "UTF-8") to php

我正在将Java Servlet Web应用程序转换为php。

我应该如何将以下 Java 命令转换为 php?

String temp = request.getParameter("q");
String temp2 = URLDecoder.decode(temp, "UTF-8");

任何帮助将不胜感激...

编辑:

这是客户端代码:

 var myJSONText = playlist.serialize();
  $.ajax({
       type : 'POST',
       url : "playlisthandler.php",
       data : {
           "q" : encodeURIComponent(myJSONText)
       },
       success : function(response) { ... },
       error : function(response) { ... },
       dataType : "json"
   });

你是说编码URIComponent是多余的吗?

你不应该有这样做的需要。servlet API中的request.getParameter()和PHP中的$_REQUEST(本质上也是$_GET$_POST已经基于请求字符编码做到了这一点。这样做的需要表明客户端通过对查询字符串组件进行双重编码而做错了。

根据您的代码,您确实在显式编码查询字符串,而 jQuery 已经在幕后执行此操作:

data : { "q" : encodeURIComponent(myJSONText) },

删除encodeURIComponent()调用,以便data变为{ "q" : myJSONText }。 jQuery已经注意它将进行URL编码。仅当您使用普通香草XMLHttpRequest时才需要encodeURIComponent()

试试这个

$paramValue = urldecode($_GET['q']);