api如何在php中使用-创新互联
这篇文章给大家分享的是有关api如何在php中使用的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。

1、用file_get_contents()函数
$params = array('key' => '8d284859d04cfeeea6b0771f754adb49',
'location' => $_COOKIE["lng"].",".$_COOKIE["lat"]);
$url3 = "http://restapi.amap.com/v3/geocode/regeo";
if (strripos('?', $url3)) {
$url4 = $url3 . http_build_query($params);
} else {
$url4 = $url3 . '?' . http_build_query($params);
}
$ret2 = json_decode(file_get_contents($url4));
var_dump($ret);2、用php的curl拓展
$url2 = 'http://www.sojson.com/open/api/weather/json.shtml';
$params = array('city' => '长沙');
if (strripos('?', $url2)) {
$url = $url2 . http_build_query($params);
}
else {
$url = $url2 . '?' . http_build_query($params);
}
$data = 'city=长沙';
$curlobj = curl_init();
curl_setopt($curlobj, CURLOPT_URL, $url);
curl_setopt($curlobj, CURLOPT_HEADER, 0);
curl_exec($curlobj);感谢各位的阅读!关于api如何在php中使用就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!
本文名称:api如何在php中使用-创新互联
文章网址:http://www.jxjierui.cn/article/docsph.html


咨询
建站咨询
