How PHP uses CURL to pass multi-dimensional arrays

Source: Internet
Author: User
Tags encode string url encode string
PHP uses CURL to pass multi-dimensional arrays. now we need to write an API, but there is a problem in passing multi-dimensional arrays when using curl to pass parameters.
 {        $post_data = array(            'auth-userid' => 611510,            'api-key' => 'api',            'domain-name'=>array('domain1','domain2'),            'tlds' => 'com',        );        $result=http_build_query($post_data);              var_dump($result);    }

When I started to use it, the domain parameter loss error always occurs. then let's take a look at the passed data.
String 'auth-userid = 611510 & api-key = api &
Domain-name % 5B0% 5D = domain1 & domain-name % 5B1% 5D = domain2 & tlds = com '(length = 93 );

What I want to upload is
'Auth-userid = 611510 & api-key = api &
Domain-name = domain1 & domain-name = domain2 & tlds = com'
If http_build_query () is used, the error "% 5B0% 5D" and "% 5B1% 5D" appear in the two-dimensional array. how can this problem be solved?


Reply to discussion (solution)

In fact, this problem is very simple.
Http_build_query? Request string generated after URL-encode
Generates a url encode string. It is already provided to encode.
You can use

$post_data = array(            'auth-userid' => 611510,            'api-key' => 'api',            'domain-name'=>array('domain1','domain2'),            'tlds' => 'com',        );        $result=http_build_query($post_data);              var_dump($result);        var_dump(urldecode($result));

In this way, the data is transmitted in the domain-name [0] = domain1 & domain-name [1] = format.

You are welcome to join the technology group to learn more technology 231566327.

% 5B0% 5D is [] a pair of square brackets
This is generated according to php rules.

If the other party is not a php user, pressDomain-name []This name is used to access the domain-name member.
Or you can delete it.
$ Result = str_replace ('% 5B0% 5D', '', http_build_query ($ post_data ));

If the other party is in php, it cannot be deleted. Otherwise, there will be less data.

The url is still given to encode.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.