获取多维数组中的url值

时间:2014-04-26 06:50:28

标签: php drupal

我在drupal页面中有如下链接,我想在项目数组中作为多维数组的avalues 比如,项目(1 =>(' productcode' =>''' mrp' =>''& #39; listprice' =>'&#39),2 =>(('产品代码' =>'',' MRP' = GT;''' listprice' = GT;''));

http://test.frontalrain.com/pricelist/edit/add?items[0][slno]=1&items[0][productcode]=Alexin&items[0][uom]=KGS&items[0][validfromdate][date]=06-04-2014&items[0][listprice]=111.00&items[0][mrp]=102.00&items[0][freight]=0.00&items[0][priceloc]=KA&items[0][states]=&items[0][city]=&items[0][storepks]=&items[0][productpk]=153&items[0][toaccountpk]=&items[0][dbaction]=&items[1][slno]=2&items[1][productcode]=Alexin&items[1][uom]=BAG20&items[1][validfromdate][date]=05-04-2014&items[1][listprice]=110.00&items[1][mrp]=101.00&items[1][freight]=0.00&items[1][priceloc]=AP&items[1][states]=&items[1][city]=&items[1][storepks]=&items[1][productpk]=153&items[1][toaccountpk]=&items[1][dbaction]=&items[2][slno]=3&items[2][productcode]=Alexin&items[2][uom]=KGS&items[2][validfromdate][date]=06-04-2014&items[2][listprice]=106.00&items[2][mrp]=102.00&items[2][freight]=0.00&items[2][priceloc]=AP&items[2][states]=&items[2][city]=&items[2][storepks]=&items[2][productpk]=153&items[2][toaccountpk]=&items[2][dbaction]=&items[3][slno]=4&items[3][productcode]=Alexin&items[3][uom]=KGS&items[3][validfromdate][date]=08-04-2014&items[3][listprice]=105.00&items[3][mrp]=200.00&items[3][freight]=0.00&items[3][priceloc]=AP&items[3][states]=&items[3][city]=&items[3][storepks]=&items[3][productpk]=153&items[3][toaccountpk]=&items[3][dbaction]=

2 个答案:

答案 0 :(得分:1)

您需要使用parse_url()parse_str()函数:

$URL = "http://test.frontalrain.com/pricelist/edit/add?items[0][slno]=1&items[0][productcode]=Alexin&items[0][uom]=KGS&items[0][validfromdate][date]=06-04-2014&items[0][listprice]=111.00&items[0][mrp]=102.00&items[0][freight]=0.00&items[0][priceloc]=KA&items[0][states]=&items[0][city]=&items[0][storepks]=&items[0][productpk]=153&items[0][toaccountpk]=&items[0][dbaction]=&items[1][slno]=2&items[1][productcode]=Alexin&items[1][uom]=BAG20&items[1][validfromdate][date]=05-04-2014&items[1][listprice]=110.00&items[1][mrp]=101.00&items[1][freight]=0.00&items[1][priceloc]=AP&items[1][states]=&items[1][city]=&items[1][storepks]=&items[1][productpk]=153&items[1][toaccountpk]=&items[1][dbaction]=&items[2][slno]=3&items[2][productcode]=Alexin&items[2][uom]=KGS&items[2][validfromdate][date]=06-04-2014&items[2][listprice]=106.00&items[2][mrp]=102.00&items[2][freight]=0.00&items[2][priceloc]=AP&items[2][states]=&items[2][city]=&items[2][storepks]=&items[2][productpk]=153&items[2][toaccountpk]=&items[2][dbaction]=&items[3][slno]=4&items[3][productcode]=Alexin&items[3][uom]=KGS&items[3][validfromdate][date]=08-04-2014&items[3][listprice]=105.00&items[3][mrp]=200.00&items[3][freight]=0.00&items[3][priceloc]=AP&items[3][states]=&items[3][city]=&items[3][storepks]=&items[3][productpk]=153&items[3][toaccountpk]=&items[3][dbaction]=";
$purl = parse_url($URL);
parse_str($purl["query"], $arr);
print_r($arr);

DEMO

答案 1 :(得分:1)

您可以使用parse_str函数,如以下代码所示。

<?php

$qs = "items[0][slno]=1&items[0][productcode]=Alexin&items[0][uom]=KGS&items[0][validfromdate][date]=06-04-2014&items[0][listprice]=111.00&items[0][mrp]=102.00&items[0][freight]=0.00&items[0][priceloc]=KA&items[0][states]=&items[0][city]=&items[0][storepks]=&items[0][productpk]=153&items[0][toaccountpk]=&items[0][dbaction]=&items[1][slno]=2&items[1][productcode]=Alexin&items[1][uom]=BAG20&items[1][validfromdate][date]=05-04-2014&items[1][listprice]=110.00&items[1][mrp]=101.00&items[1][freight]=0.00&items[1][priceloc]=AP&items[1][states]=&items[1][city]=&items[1][storepks]=&items[1][productpk]=153&items[1][toaccountpk]=&items[1][dbaction]=&items[2][slno]=3&items[2][productcode]=Alexin&items[2][uom]=KGS&items[2][validfromdate][date]=06-04-2014&items[2][listprice]=106.00&items[2][mrp]=102.00&items[2][freight]=0.00&items[2][priceloc]=AP&items[2][states]=&items[2][city]=&items[2][storepks]=&items[2][productpk]=153&items[2][toaccountpk]=&items[2][dbaction]=&items[3][slno]=4&items[3][productcode]=Alexin&items[3][uom]=KGS&items[3][validfromdate][date]=08-04-2014&items[3][listprice]=105.00&items[3][mrp]=200.00&items[3][freight]=0.00&items[3][priceloc]=AP&items[3][states]=&items[3][city]=&items[3][storepks]=&items[3][productpk]=153&items[3][toaccountpk]=&items[3][dbaction]=";

parse_str( $qs, $out );
print_r( $out );

?>

HTH