/*以post的方式,请求url $data为数组参数 */
function post($url, $data){
$postdata = http_build_query($data);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
return $result;
}
/*把字符串url参数转换为数组*/
function convertUrlQuery($query)
{
$queryParts = explode('&', $query);
$params = array();
foreach ($queryParts as $param)
{
$item = explode('=', $param);
$params[$item[0]] = $item[1];
}
return $params;
}