我觉得我在通过PHP获取ecoded URL中的查询字符串值时遇到了一些基本错误。
有人可以指导最新的方法从PHP下面获取PHP中的查询字符串值。
http%3A%2F%2Fwwww.mycompany.org%2FmyStatusListener%3FmtmId%3D%25MTMID%25%26statusCode%3D%25 -
STATUSCODE%25%26statusDate%3D%25STATUSDATE%25%26mnc%3D%25MNC%25%26mcc%3D%25MNC%25%26 -
blocked%3D%25BLOCKED%25%0A
非常感谢
答案 0 :(得分:1)
只需使用rawurldecode,parse_url和parse_str,就像这样:
$a="http%3A%2F%2Fwwww.mycompany.org%2FmyStatusListener%3FmtmId%3D%25MTMID%25%26statusCode%3D%25STATUSCODE%25%26statusDate%3D%25STATUSDATE%25%26mn25MNC%25%26mcc%3D%25MNC%25%26blocked%3D%25BLOCKED%25%0A";
$b=rawurldecode($a);
$c=parse_url($b,PHP_URL_QUERY);
parse_str($c,$d);
print_r($d);
答案 1 :(得分:-1)
使用urldecode,请参阅此处的示例http://codepad.org/jANpV0Vz
<强>更新强>
示例:
$s = 'http%3A%2F%2Fwwww.mycompany.org%2FmyStatusListener%3FmtmId%3D%25MTMID%25%26statusCode%3D%25STATUSCODE%25%26statusDate%3D%25STATUSDATE%25%26mnc%3D%25MNC%25%26mcc%3D%25MNC%25%26blocked%3D%25BLOCKED%25%0A';
$url = urldecode($s);
$query = parse_url($url, PHP_URL_QUERY);
$elements = explode('&', $query);
$result = array();
foreach ($elements as $element) {
list($k, $v) = explode('=', $element);
$result[$k] = $v;
}
print_r($result);