- 活動報導.php
主程式,抓取資網中心的活動報導用。 - SchoolNews.htm
靜態網頁,將上面抓到的最新幾則報導放入,顯示在首頁。 - 參考網頁:
<?php
//顯示錯誤訊息
//ini_set('display_errors', 1);
//相關 CSS & js
$display = <<<END_head
<link rel="stylesheet" type="text/css" href="http://www.tc.edu.tw/themes/web2011/css/960grid/960.css" media="screen" />
<link type="text/css" href="http://www.tc.edu.tw/js/jquery-ui/themes/flick/jquery.ui.all.css" media="screen" rel="stylesheet" />
<link href="http://www.tc.edu.tw/css/popeye/jquery.popeye.css" media="screen" rel="stylesheet" type="text/css" >
<link href="http://www.tc.edu.tw/css/popeye/jquery.popeye.style.css" media="screen" rel="stylesheet" type="text/css" >
<script type="text/javascript" src="http://www.tc.edu.tw/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="http://www.tc.edu.tw/js/jquery-ui-1.8.9.custom.min.js"></script>
<script type="text/javascript" src="http://www.tc.edu.tw/js/jquery.hoverIntent.minified.js"></script>
<script type="text/javascript" src="http://www.tc.edu.tw/js/plugins/jquery-idleTimeout.js"></script>
<script type="text/javascript" src="http://www.tc.edu.tw/js/plugins/jquery.popeye-2.0.4.min.js"></script>
<!--
.news_content {padding:5px; font-size:1.1em;}
.news_content:first-letter { font-weight: bold; font-size: 180%; float: left; color: #0055cc; margin:3px;}
.meta {text-align:right;padding:5px; font-style: italic;}
.meta a:HOVER {text-decoration: underline;}
#main_content h3 {font-size:1.3em; }
.news_more a, .meta a{color:navy; font-weight: bold;}
#sidebar h4 {color:#33a;font-size:1.2em}
#sidebar li {color:#355; list-style: none; margin:3px}
.item-list a {color:#33a;font-weight: normal;}
.item-list a:HOVER {color:#655}
.item-list li {
background : url(/images/icon01.jpg) left no-repeat;
margin: 3px;
padding-left:20px;
padding-bottom: 5px;
border-bottom: thin dotted #ccc;
}
.news_tags {background: #cce;padding:3px;margin:5px 0;}
.favoriteDiv {text-align:right; border-top: thin dotted #ccc; padding:3px; margin-top: 30px}
.favorite {
width: 16px;
height: 16px;
background-repeat:no-repeat;
padding-left: 20px;
padding-top: 0px;
background-image: url("/images/icons/heart.png");
}
#favorite_count,.favorite_count {margin:3px; color:#e33; font-weight: bold;}
.last_update_time {border-top:thin dotted #ccc; padding-top:15px; margin-top:10px;text-align: right; font-style: italic; font-size:85%}
.sub_title {margin: 0 0 10px 0; pagging:0px ;text-align: center; font-size: 16px; color: #03e;}
.support_count {color:#f30}
/* Tag cloud */
.tags {
margin:0.3em;
padding:.5em 10px;
text-align:center;
background:#71b5e9 url(/css/images/bg_tags.gif) repeat-x;
}
.tags a{
text-decoration:none;
color:#fff;
padding:0 2px;
}
.tags a:hover{
color:#cff400;
}
.tag1{font-size:100%;}
.tag2{font-size:120%;}
.tag3{font-size:140%;}
.tag4{font-size:160%;}
.tag5{font-size:180%;}
/* alternative layout */
.tags .alt{
text-align:left;
padding:0;
background:none;
}
.tags .alt li{
padding:2px 10px;
background:#efefef;
display:block;
}
.tags .alt .tag1,
.tags .alt .tag2,
.tags .alt .tag3,
.tags .alt .tag4,
.tags .alt .tag5{font-size:100%;}
.tags .alt .tag1{background:#7cc0f4;}
.tags .alt .tag2{background:#67abe0;}
.tags .alt .tag3{background:#4d92c7;}
.tags .alt .tag4{background:#3277ad;}
.tags .alt .tag5{background:#266ca2;}
/* // Tag cloud */
-->
<script>
$(function(){
$('.ppy').popeye();
});
</script>
END_head;
//活動報導網頁
$url = "http://www.tc.edu.tw/SchoolNews/show/school/id/458";
//抓取網頁內容
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$contents = curl_exec($ch);
curl_close($ch);
//echo $contents;
//替換掉一些鏈結
$contents=str_replace ("/upload/","http://www.tc.edu.tw/upload/",$contents);
$contents=str_replace ("/SchoolNews/","http://www.tc.edu.tw/SchoolNews/",$contents);
//取出相關內容,並儲存至陣列 match
preg_match_all('/<h3 [^>]*class="ui-widget-header ui-corner-top"[^>]*>(.*?)<\/h3>/si',$contents,$match[0]);
preg_match_all('/<p [^>]*class="meta"[^>]*>(.*?)<\/p>/si',$contents,$match[1]);
preg_match_all('/<div [^>]*class="ppy newsppy"[^>]*>(.*?) <\/span>[^.]*<\/div>[^.]*<\/div>/si',$contents,$match[2]);
preg_match_all('/<div[^>]*class="news_content"[^>]*>(.*?)<\/div>/si',$contents,$match[3]);
//取出最前面幾則報導
$show=3;
for ($i=0; $i<$show; $i++)
{
for ($j=0; $j<=3; $j++)
{
$display=$display.$match[$j][0][$i]."\n\n";
}
$display=$display."<div class=\"clear\"></div>\n\n";
}
$display=iconv("UTF-8","big5",$display);
echo $display;
$display=$display."<br><br><a href=\"/cnes/活動報導.php\" target=_blank>更新活動報導</a>";
//寫入 HTML 檔
$file=fopen("SchoolNews.htm","w");
fwrite($file,$display);
fclose($file);
?>
沒有留言:
張貼留言