php - creating array to be used with http_build_query -


how rewrite this?

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

into this?

$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}"                     ); 

i'm curious last part of parameters. sms( array or something? did write correctly inside array?

...&msg_type=sms(&<property_name>=<property_value>) 

if query string url, parameter value sms(&...) should have been encoded sms(%26...) distinguish ampersand character value ampersand used separate different parameters. parentheses should encoded sms%28%26...%29.

other that, thing inside sms(...) parameter value meant parsed receiver of query, , has no special meaning url itself.

your array re-formulation appears correct, except missing closing paren in msg_type value:

<?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 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -