http_build_query忽略一个键

时间:2017-04-03 14:25:45

标签: php query-string

我的网址变为带有http_build_query功能的查询字符串。

但是我有一个参数timestamp我无法编辑。 &times成为乘法符号x

有解决方法吗?

这是我传递给http_build_query函数的数组。

$parameters =   array(
            "transaction_id"=>uniqid("FF-"),
            "timestamp"=> time(),
            "order_total"=>$_SESSION['total_price'],
            "order_total_with_vat"=>$_SESSION['total_price'] * 1.21,
            "order_vat"=>"21",
            "payment_method"=>"ideal",
            "payment_status"=>"1",
            "customer_name"=>$_SESSION['customer_data']['naam'],
            "customer_address"=>$_SESSION['customer_data']['address'],
            "customer_city"=>$_SESSION['customer_data']['city'],
            "customer_zipcode"=>$_SESSION['customer_data']['zipcode'],
            "customer_country"=>$_SESSION['customer_data']['country'],
            "customer_email"=>$_SESSION['customer_data']['email'],
            "customer_telephone"=>$_SESSION['customer_data']['telephone'],
        );

输出网址:

http://somedomain/subdir/someapi/order?transaction_id=FF-58e2451c5aea9×tamp=1491223836&order_total=156695&order_total_with_vat=189600.95&order_vat=21&payment_method=ideal&payment_status=1&customer_name=t&customer_address=t&customer_city=t&customer_zipcode=t&customer_country=t&customer_email=t%40t&customer_telephone=t&product%5B0%5D=5&product%5B1%5D=5&product%5B2%5D=5&product%5B3%5D=5&product%5B4%5D=5&product%5B5%5D=5&product%5B6%5D=5

优先输出:

http://somedomain/subdir/someapi/order?transaction_id=FF-58e2451c5aea9&timestamp=1491223836&order_total=156695&order_total_with_vat=189600.95&order_vat=21&payment_method=ideal&payment_status=1&customer_name=t&customer_address=t&customer_city=t&customer_zipcode=t&customer_country=t&customer_email=t%40t&customer_telephone=t&product%5B0%5D=5&product%5B1%5D=5&product%5B2%5D=5&product%5B3%5D=5&product%5B4%5D=5&product%5B5%5D=5&product%5B6%5D=5

http_build_query功能:

case 'POST':
    curl_setopt( $curlHandler, CURLOPT_POST, true );
    $url    .= '?' . http_build_query( $parameters );
    break;

2 个答案:

答案 0 :(得分:4)

目前它正常运作。问题在于,当您回显网址时,序列&times将使您的浏览器将其替换为乘法符号x。要回显它并在浏览器中显示正确的方法,请尝试以下方法:

echo htmlspecialchars($url); 

这将显示所需的URL。

答案 1 :(得分:1)

@Novice是对的,他评论了我的问题:

  

它只是浏览器中的显示问题,但您的卷曲数据将与您在优先输出中显示的内容一样,无需添加任何额外的内容即可! - 新手

当我检查apache access.log时,我可以看到已发布的优先查询字符串。