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.