php http_build_query忽略一个关键字

koaltpgm  于 2023-01-29  发布在  PHP
关注(0)|答案(2)|浏览(128)

我有一个URL,它通过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'],
        );

url的输出:

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;
o8x7eapl

o8x7eapl1#

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

echo htmlspecialchars($url);

这将显示所需的URL。

ui7jx7zq

ui7jx7zq2#

@新手说对了,他评论我的问题:
这只是浏览器中的一个显示问题,但您的curl数据会像您在首选输出中显示的那样,无需添加任何额外的内容,只需点击即可!-新手
当我检查apache access.log时,我可以看到发布的首选查询字符串。

相关问题