萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> php curl_init() 實例

php curl_init() 實例

php curl_init() 實例

function ip($date){
 $rul="http://111cn.net/s?ie=gbk&sr=&z=&cl=3&f=8&wd=$date&ct=0&tn=downreg";
 $ch = curl_init();
 $timeout = 5;
 curl_setopt ($ch, CURLOPT_URL, "$rul");
 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
 curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
 $contents = curl_exec($ch);
 curl_close($ch);
 preg_match_all("/    來自:(.*?)      此數據由/is",$contents,$address);
 if(empty($address[1][0]))$address[1][0]='未知';
 return $address[1][0];
}

copyright © 萬盛學電腦網 all rights reserved