创建要与http_build_query一起使用的数组

时间:2015-04-25 06:37:27

标签: php

我该如何重写?

command=v&amount=<amount>&currency=<currency>&client_ip_addr=<ip>&description=<desc>&language=<language>&msg_type=SMS(&<property_name>=<property_value>)

进入这个?

$post_fields = array(
                     'command'        => 'v',
                     'amount'         => $amount,
                     'currency'       => $currency,
                     'client_ip_addr' => $client_ip_addr,
                     'description'    => $description,
                     'language'       => $language,
                     'msg_type'       => "SMS(&${property_name}={$property_value}"
                    );

我对最后一部分参数感到好奇。 SMS(它是一个数组还是什么?我在数组内部写得正确吗?

1 个答案:

答案 0 :(得分:0)

SMS(&...)

如果这是来自URL的查询字符串,则参数值SMS(%26...)应该已编码为SMS%28%26...%29,以将&符号区分为用于分隔不同参数的&符号的字符值。括号应该类似地编码为SMS(...)

除此之外,msg_type参数值内的东西可能是由查询的接收者解析的,对URL本身没有特殊意义。

您的阵列重新配置似乎是正确的,除了您错过了<?php $amount = '$3.99'; $currency = 'USD'; $client_ip_addr = '2001:db8::42'; $description = 'Flumbar'; $language = 'en'; $property_name = 'glimb'; $property_value = 'snord'; $post_fields = array( 'command' => 'v', 'amount' => $amount, 'currency' => $currency, 'client_ip_addr' => $client_ip_addr, 'description' => $description, 'language' => $language, 'msg_type' => "SMS(&${property_name}={$property_value})" ); $s = http_build_query ($post_fields); echo "$s\n"; // command=v&amount=%243.99&currency=USD&client_ip_addr=2001%3Adb8%3A%3A42& // description=Flumbar&language=en&msg_type=SMS%28%26glimb%3Dsnord%29 值中的结束值:

{{1}}