php远程读取json的方法

<?php


/**
 * @author 懒人 <service@kuitao8.com>
 * @since 2.0
 */
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);

 转载:http://www.kuitao8.com/20150108/3439.shtml

原文地址:https://www.cnblogs.com/wawahaha/p/4600652.html