php教程

curl函数获取API接口数据方法

php教程 51源码 11-02 人阅读

PHP利用curl函数,获取API接口数据方法示例代码,自用收藏

<?php 
 $weather = curl_init();  
      curl_setopt($weather,CURLOPT_URL,"https://api.pc2801.com/cqssc/".time());  
      curl_setopt($weather, CURLOPT_SSL_VERIFYPEER, false); //如果接口URL是https的,我们将其设为不验证,如果不是https的接口,这句可以不用加 
      curl_setopt($weather,CURLOPT_RETURNTRANSFER,true); 
      $data = curl_exec($weather);  
      curl_close($weather);      
      $data=json_decode($data,true);//将json格式转化为数组格式,方便使用 
?>


标签 PHP函数 php代码