php 星座运势_php实例之新浪星座运势

function html2txt($document){

$search = array('@@si',  // Strip out javascript

'@]*?>@si',           // Strip out HTML tags

'@@siU',   // Strip style tags properly

'@@',       // Strip multi-line comments including CDATA

'@\s+| @'

);

$text = preg_replace($search, '', $document);

return $text;

} www.jbxue.com

function curl($url){

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_REFERER, 'http://astro.sina.com.cn/fate/astro_aries.html?prourl=0');//伪造来源

curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/'.mt_rand(2, 9).'.0 (Windows NT 6.1; WOW64; rv:'.mt_rand(10, 30).'.0) Gecko/'.mt_rand(2000, 2014).'0101 Firefox/'.mt_rand(10, 30).'.0');//随机header

curl_setopt($ch, CURLOPT_HEADER, 0);

$data = curl_exec($ch);

curl_close($ch);

return $data;

}

foreach(array($constellation) as $astro){

preg_match('/(.*?)(.*?).*?有效日期:(.*?)综合运势(.*?)爱情运势(.*?)工作状况(.*?)理财投资(.*?)健康指数(.*?)商谈指数(.*?)幸运颜色(.*?)幸运数字(.*?)速配星座(.*?)

(.*?)/isu', curl('http://vip.astro.sina.com.cn/astro/view/'.$astro.'/day/'), $matches);

file_put_contents($astro, json_encode(array($matches[1], $matches[2], html2txt($matches[3]), substr_count($matches[4], '

unset($matches);

$array=json_decode(file_get_contents($astro),true);

}

//明天的日期

$mingtian=date('Ymd',strtotime('+1 day'));

foreach(array($constellation) as $astro){

preg_match('/(.*?)(.*?).*?有效日期:(.*?)综合运势(.*?)爱情运势(.*?)工作状况(.*?)理财投资(.*?)健康指数(.*?)商谈指数(.*?)幸运颜色(.*?)幸运数字(.*?)速配星座(.*?)

(.*?)/isu', curl('http://vip.astro.sina.com.cn/astro/view/'.$astro.'/day/'.$mingtian.''), $matches);

//这样正则,可以更小的受新浪改版所带来的影响

file_put_contents($astro, json_encode(array($matches[1], $matches[2], html2txt($matches[3]), substr_count($matches[4], '

unset($matches);

$array2=json_decode(file_get_contents($astro),true);

}

//今天的运势

print_r($array)

//明天的运势

print_r($array2)

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值