星座--抓取其他网站的信息

原创
2017/10/18 15:13
阅读数 94
<?php
header("Content-type:text/html;charset=utf-8");
/**
 *gemini 双子座
 *aries 白羊座
 *taurus 金牛座
 *cancer 巨蟹座
 *leo 狮子座
 *virgo 处女座
 *libra 天秤座
 *scorpio 天蝎座
 *sagittarius 射手座
 *capricorn 摩羯座
 *aquarius 水瓶座
 *pisces 双鱼座
 */
/*
function week($num){
	$week = array('一','二','三','四','五','六','七');
	return $week[$num-1];
}
$jd=cal_to_jd(CAL_GREGORIAN,date("m"),date("d"),date("Y"));
$num = jddayofweek($jd);
echo '今天是星期'.week($num).'<br>';exit;
*/
function constellation($month,$day){
	//检查参数有效性
	if($month<1||$month>12||$day<1||$day>31) return false;	
	//星座名称以及开始日期
	$constellations=array(
		array("20"=>array("水瓶座",'aquarius')),
		array("19"=>array("双鱼座",'pisces')),
		array("21"=>array("白羊座",'aries')),
		array("20"=>array("金牛座",'taurus')),
		array("21"=>array("双子座",'gemini')),
		array("22"=>array("巨蟹座",'cancer')),
		array("23"=>array("狮子座",'leo')),
		array("23"=>array("处女座",'virgo')),
		array("23"=>array("天秤座",'libra')),
		array("24"=>array("天蝎座",'scorpio')),
		array("22"=>array("射手座",'sagittarius')),
		array("22"=>array("摩羯座",'capricorn'))
	);
	list($constellation_start,$constellation_name)=each($constellations[(int)$month-1]);
	if($day<$constellation_start){
		list($constellation_start,$constellation_name)=each($constellations[($month-2<0)?$month=11:$month-=2]);
	}
	return $constellation_name;
}
$month = date("m");
$day = date("d");
$constellation = constellation($month,$day);
if(empty($_GET['astro'])){
	$astro = $constellation['1'];
}else{
	$astro = $_GET['astro'];
}
//$url ="http://www.xzw.com/fortune/".$astro;
//$data = file_get_contents($url);

//初始化
$ch = curl_init();
//设置选项,包括URL
curl_setopt($ch,CURLOPT_URL,'http://www.xzw.com/fortune/'.$astro);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_HEADER,0);

//执行并获取HTML文档内容
$data = curl_exec($ch);
//释放curl句柄
curl_close($ch);

$data=preg_replace("/[\t\n\r]+/","",$data);
$partern='/<dl>.*?<\/dl>/';   
preg_match_all($partern,$data,$result);   
$constellation = $result[0][1];

$conpart = '/<div class=\"c_cont\">.*?<\/div>/ism';
preg_match_all($conpart,$data,$res); 
$con = $res[0][0]; 
?>
<html>
<head>
	<title>星座运势</title>
	<meta charset="utf-8">
	<meta content="width=device-width,user-scalable=no" name="viewport">
	<meta name="x5-orientation" content="portrait">
	<meta name="screen-orientation" content="portrait">
	<meta content="yes" name="apple-mobile-web-app-capable">
	<meta content="yes" name="apple-touch-fullscreen">
	<meta content="telephone=no,email=no" name="format-detection">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="shortcut icon" href="/default/astro/favicon.ico">
    <link rel="bookmark" href="/default/astro/favicon.ico">
	<script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js"></script>
	<script src="https://code.jquery.com/jquery.js"></script>
	<script src="../astro/js/main.js"></script>
	<link rel="stylesheet" href="../astro/css/style.css" type="text/css" />
	<link rel="stylesheet" href="../astro/css/astro.css" type="text/css" />
</head>
<body style="font-size:24px;">
	<div class="header">
		<div class="header_box">
			<a href='/default/astro/date.php' class="logo">
				<img src="../astro/images/tellme_logo.png" />
			</a>
			<!--
			<span class="title">星座运势</span>
			-->
			<div class="menu" id="menu"></div>
			<div class="close-menu" id="close-menu"></div>
		</div>
	</div>
	<div class="hide-nav">
		<ul class="nav-box">
			<li class="nav-list">
				<a class="btn" href="?astro=gemini">
					<img src="../astro/astro/gemini.png" />
					<span>双子座</span>
				</a>
			</li>
			<li class="nav-list">
					<a class="btn" href="?astro=aries">
						<img src="../astro/astro/aries.png" />
						<span>白羊座</span>
					</a>
			</li>
			<li class="nav-list">
				<a class="btn" href="?astro=taurus">
					<img src="../astro/astro/taurus.png" />
					<span>金牛座</span>
				</a>
			</li>
			<li class="nav-list">
				<a class="btn" href="?astro=cancer">
					<img src="../astro/astro/cancer.png" />
					<span>巨蟹座</span>
				</a>
			</li>
			<li class="nav-list">
				<a class="btn" href="?astro=leo">
					<img src="../astro/astro/leo.png" />
					<span>狮子座</span>
				</a>
			</li>
			<li class="nav-list">
				<a class="btn" href="?astro=virgo">
					<img src="../astro/astro/virgo.png" />
					<span>处女座</span>
				</a>
			</li>
			<li class="nav-list">
				<a class="btn" href="?astro=libra">
					<img src="../astro/astro/libra.png" />
					<span>天秤座</span>
				</a>
			</li>
			<li class="nav-list">
				<a class="btn" href="?astro=scorpio">
					<img src="../astro/astro/scorpio.png" />
					<span>天蝎座</span>
				</a>
			</li>
			<li class="nav-list">
				<a class="btn" href="?astro=sagittarius">
					<img src="../astro/astro/sagittarius.png" />
					<span>射手座</span>
				</a>
			</li>
			<li class="nav-list">
				<a class="btn" href="?astro=capricorn">
					<img src="../astro/astro/capricorn.png" />
					<span>摩羯座</span>
				</a>
			</li>
			<li class="nav-list">
				<a class="btn" href="?astro=aquarius">
					<img src="../astro/astro/aquarius.png" />
					<span>水瓶座</span>
				</a>
			</li>
			<li class="nav-list">
				<a class="btn" href="?astro=pisces">
					<img src="../astro/astro/pisces.png" />
					<span>双鱼座</span>
				</a>
			</li>
		</ul>
	</div>
	<div id="view">
		<?php echo $constellation;?>
	</div>
	<div id="con">
		<?php echo $con;?>
	</div>
</body>
<script type="text/javascript" src="http://webmonkey.d17.cc/js/jquery/toucher/toucher.js"></script>
<script>
	var img = $('#view dl dt img ');
	var astro = '<?php echo $astro;?>';
	img.attr('src','../astro/astro/'+astro+'.png');
	
	$(function(){
        mainindex.homepage();
    })
</script>
</html>
展开阅读全文
打赏
0
1 收藏
分享
加载中
更多评论
打赏
0 评论
1 收藏
0
分享
返回顶部
顶部