php远程读取json的方法

180it 2019-11-04 AM 3088℃ 0条

<?php
header("Access-Control-Allow-Origin: *");
header("Content-type:text/html;charset=utf-8");
function GetCurl($url){

$curl = curl_init();
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl,CURLOPT_URL, $url);
curl_setopt($curl,CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$resp = curl_exec($curl);
curl_close($curl);
return $resp;

}
$resp = GetCurl("http://www.kuitao8.com/api/joke");
$resp = json_decode($resp,true);
header('Content-type: application/json');
echo json_encode($resp);

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

php远程读取json的方法