A problem with Http_build_query in PHP _php tips

Source: Internet
Author: User
When we use curl to post data, we need to set the post data
curl_setopt ($c, Curlopt_postfields, $post _data);

If the $data here is
Copy Code code as follows:

$data = Array (
' Name ' => ' Scofield ',
' Time ' => ' 2012-2-3 '
)

Next, you need to turn $data into a string
$post _data = Http_build_query ($data);
And the use of http_build_query conversion and then
curl_setopt ($c, Curlopt_postfields, $post _data);

There seems to be no problem. In practice, however, the $post _data was not post. So, I wrote a conversion method after the OK.
Copy Code code as follows:

function Getstr ($array, $Separator = ' & ') {
if (empty ($array))
Return
if (!is_array ($array)) {
return $array;
}
$returnStr = ';
foreach ($array as $key => $val) {
$temp = ';
if (Is_array ($val)) {
for ($i = 0; $i < count ($val); $i + +) {
$returnStr. = $key. ' ['. $i. ']' . '=' . $val [$i]. $Separator;
}
} else {
$returnStr. = $key. '=' . $val. $Separator;
}
}
$RETURNSTR = substr (Trim ($RETURNSTR), 0,-1);
return $returnStr;
}

Thanks to Accouts-huangbin's Test http_build_query ($data, "", "&"); You don't have to write your own method to parse it.

Http_build_query remote attackers can exploit vulnerabilities to obtain sensitive memory information. Please use them carefully.

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.