Tag: curl php 笑话
//此接口每天更新10条笑话 $url = "http://api.laifudao.com/open/xiaohua.json"; $ret = http_request($url); $arr = json_decode( trim($ret,chr(239).chr(187).chr(191)) ,true); //过滤掉BOM头 shuffle($arr); //随机数组 print_r($arr); //输出数组 function http_request( $url ){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 0 ); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0 ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); if( $data === false ){ echo 'Curl error: ' . curl_error($ch); } curl_close($ch); return $data; }