Beautiful goodbye php http_build_query a problem

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 are

Copy the 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);
With http_build_query conversion,
curl_setopt ($c, Curlopt_postfields, $post _data);
There seems to be no problem. But in practice, the $post _data is not post past. So, I wrote a conversion method after the OK.

Copy the 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;
}


Thank bin Huang-huangbin children's shoes test http_build_query ($data, "", "&"); , you do not have to write your own method of parsing.
Http_build_query remote attackers can exploit vulnerabilities to obtain sensitive memory information. Please use it carefully.

The above describes a beautiful goodbye php http_build_query a problem, including the beautiful goodbye aspect of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.