dongquqiao2010 2016-10-31 14:43
浏览 15
已采纳

PHP在Get函数中提取Subordinate Info

I'm a complete newb to PHP - I tried researching this problem, but haven't found an answer. I'm using Formstack to create an order form for a non-profit. At the end of the process, formstack appends all of the entered data to the URL. Typically, I use a simple PHP GET to pull the information I need. In this instance, however, there is a second layer of data after the = of the primary item's name.

Each item shows up similar to this (example items is Chickens):

&chickens=charge_type+%3D+fixed_amount%0Aquantity+%3D+2%0Aunit_price+%3D+15.00%0Atotal+%3D+30&

I need to pull quantity=2, where quantity is a subordinate value of chickens. My knowledge ends at pulling the entire string following chickens=

<?php echo htmlspecialchars($_GET["chickens"]); ?>

Which results in: charge_type = fixed_amount quantity = 2 unit_price = 15.00 total = 30

Any thoughts would be greatly appreciated. Thanks!

  • 写回答

1条回答 默认 最新

  • dongyuandou2521 2016-10-31 15:02
    关注

    Depending on what you are going to do, you could transform the values in Chicken Array form:

    // separate all the value-key pairs in chicken into an array
    $array = explode("
    ", $_GET["chickens"]);
    
    // init an array that will store all values as associative array
    $chickens = array();
    
    foreach($array as $valuepair) {
        // go too the key-value-pairs and split them at the "=" char
        $tmp = explode("=", $valuepair);
        // add value under keyname to array and remove some spaces with trim function 
        $chickens[trim($tmp[0])] = trim($tmp[1]);
    }
    
    // show what we got as key-values, as debug output 
    print_r($chickens);
    
    // show one value of the array
    echo $chickens['quantity'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大