如何解码由http_build_query编码的url

时间:2017-04-27 09:36:19

标签: php

我想在url中传递数组,所以我使用http_build_query

编码
$filterArray = array('OrderNo'=>$_REQUEST['txtorderno'],
                         'StoreName'=>$_REQUEST['txtstorename'],
                         'PartyCode'=>$_REQUEST['txtpartycode'],
                         'fromdate'=>$_REQUEST['txtfromdate'],
                         'todate'=>$_REQUEST['txttodate'],
                         'minamount'=>$_REQUEST['txtminamount'],
                         'maxamount'=>$_REQUEST['txtmaxamount']);

$data = array('DistributorId' => $_GET['DistributorId'], 'StoreId' => $_GET['StoreId'],'filterArray' => http_build_query($filterArray));

最后我的网址就像这样生成

http://localhost/test/orderdetails.php?DistributorId=&StoreId=&filterArray=OrderNo%3D1%26StoreName%3D2%26PartyCode%3D3%26fromdate%3D04%252F26%252F2017%26todate%3D04%252F27%252F2017%26minamount%3D111%26maxamount%3D222

现在如何从url获取所有参数?

我试图打印filterArray参数,如

echo "<pre>";
$arr = (urldecode($_GET['filterArray']));
var_dump($arr);

打印

string(99) "OrderNo=1&StoreName=2&PartyCode=3&fromdate=04/26/2017&todate=04/27/2017&minamount=111&maxamount=222"

1 个答案:

答案 0 :(得分:3)

您可以使用parse_str [1]:

<?php
$inputStr = 'OrderNo=1&StoreName=2&PartyCode=3&fromdate=04/26/2017&todate=04/27/2017&minamount=111&maxamount=222';

parse_str($inputStr, $output);

var_dump($output);
?>

示例:https://3v4l.org/toiKf

[1]:http://php.net/manual/de/function.parse-str.php