천

rss 읽어오기 입니다.

· 2016-01-21 (목) 00:29:19 · 2609

<?php

//캐쉬기능추가
//1. 이파일과 동일한 경로에 cashe 라는 디렉토리를 생성한다.
//2. 퍼미션은 777로 준다.
$cashe_time = '10';//분단위, 숫자만
$cashe_dir = 'cashe';// /를 뺀 순수한 디렉토리명만
$cashe_file = preg_replace("`^(.*)(/[^/]+)$`", "\\1/" . $cashe_dir . "\\2", __FILE__);
if (!is_dir("./" . $cashe_dir)) {

  echo "캐쉬 디렉토리가 존재하지 않습니다.";
  exit;
}

//캐쉬 파일이 존재하고, 수정된 시간이 지정된 시간을 넘지 않았을 경우 인클루드 후 종료
if (is_file($cashe_file) && (filemtime ($cashe_file) + ($cashe_time * 60) > time())){

  include $cashe_file;
  exit;
}

ob_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Rss 읽어오기</title>
<style>
body {margin:0px 10px 3px 10px;padding:0}
body,td,select {font-family:Verdana,Gulim;font-size:9pt;}
td {overflow:hidden;text-overflow:ellipsis;}
td.description p {margin:0;padding:3 0 3 0;}
a.lnk1:link,a.lnk1:visited,a.lnk1:hover {color:#0000ff;text-decoration:underline;}
a.lnk2:link,a.lnk2:visited {color:#808080;text-decoration:none;}
a.lnk2:hover {text-decoration:underline;}
a.lnk3:link {color:#0000ff;text-decoration:none;}
a.lnk3:visited {color:#800080;text-decoration:none;}
a.lnk3:hover {text-decoration:underline;}
a.lnk4:link,a.lnk4:visited {color:#D2691E;text-decoration:none;}
a.lnk4:hover {text-decoration:underline;}
a.lnk5:link,a.lnk5:visited {color:#0000ff;text-decoration:none;}
a.lnk5:hover {background-color:#eeeeee;}
.header1 {font-weight:bold;font-size:12pt;}
.btn_submit1 {border:1px solid gray;width:40;height:20;background-color:white;font-family:Gulim;font-size:9pt;padding:2 0 0 0}
.btn_submit2 {border:1px solid #c0c0c0;width:34;height:18;background-color:white;font-family:Gulim;font-size:8pt;line-height:12pt}
</style>
<base target=_blank>
</head>
<body bgcolor='#ffffff'>
<?php

//올블로그 명예의전당 rss 글내용이 하루에 한번만 바뀝니다.
$url = "http://www.allblog.net/Rss/BestPosts.xml";

$result = file($url);
$text = implode("\n", $result);

if(!empty($text)){ 
 
  $item = explode("<item>", $text);
  $count = count($item);

  echo "
<table width=100% border=0 cellpadding=0 cellspacing=0 style=\"table-layout:fixed;\">
 <tr><td>
 <table width=100% border=0 cellpadding=0 cellspacing=0 style=\"table-layout:fixed;\">
 <tr>
 <td align=right valign=top style=\"padding:0 4 0 0;font-size:8pt;color:gray\" nowrap>총 <b>" . ($count - 1) . "</b>개  |  최종업데이트: " . date("Y-m-d H:i") . "</td>
 </tr>
 </table>

 </td></tr>
 <tr><td height=4></td></tr>
</table>
  ";

  if (is_array($item) && count($item) > 1) {

    for ($i = 1; $i < $count; $i++){

      preg_match_all("`<title>(.+)</title><link>(.+)</link><source url=\".+\">(.+)</source><category>([^<]+)</category>(<category>([^<]+)</category>)?(<category />)?<pubDate>(.+)</pubDate><description><!\[CDATA\[(.+)\]\]></description>`s", $item[$i], $matches);

      if (is_array($matches[1]) && count($matches[1]) > 0) {

        foreach($matches[1] as $key => $val){

          $title = (!empty($val)) ? $val : '';
          $link = (!empty($matches[2][$key])) ? $matches[2][$key] : '';
          $source = (!empty($matches[3][$key])) ? $matches[3][$key] : '';
          $category1 = (!empty($matches[4][$key])) ? $matches[4][$key] : '';
          $category2 = (!empty($matches[6][$key])) ? $matches[6][$key] : '';
          $category = (!empty($category1) && !empty($category2)) ? $category1 . ", " . $category2 : $category1 . $category2;
          $pubDate = (!empty($matches[8][$key])) ? date("Y-m-d H:i", strtotime($matches[8][$key])) : '';
          $description = (!empty($matches[9][$key])) ? $matches[9][$key] : '';
          $description_len = number_format(strlen($description));

          if (!preg_match("`(<\s*\t*img\s*\t*|<\s*\t*a\s*\t*href)`i", $description)) $description = strip_tags(str_replace(array("<", ">", "<br /><hr />위 내용은 올블로그가 올블로그에 등록한 블로그로부터 수집하여 서버에 저장하고 있는 내용의 전체 또는 일부 입니다. 이 게시물에 대한 모든 저작권과 책임은 해당 블로그의 등록자에게 있습니다."), array("<", ">", ""), $description)) . "<br /><hr />위 내용은 올블로그가 올블로그에 등록한 블로그로부터 수집하여 서버에 저장하고 있는 내용의 전체 또는 일부 입니다. 이 게시물에 대한 모든 저작권과 책임은 해당 블로그의 등록자에게 있습니다.";

          echo "
<a href=\"" . $link . "\"></a>
<table width=100% border=0 cellpadding=0 cellspacing=0>
<tr><td bgcolor=#bdb76b><img width=1 height=1 alt=\"\"></td></tr>
<tr><td bgcolor=#ebebd5 style='padding:5 2 6 2'>
  <table width=100% border=0 cellpadding=0 cellspacing=0>
  <tr><td style=\"font-size:10pt\"><a href=\"" . $link . "\"><span style=\"font-weight:bold\">" . $title . "</span></a></td></tr>
  </table>
</td></tr>
<tr><td style='padding:4 2 0 2'>
  <table width=100% border=0 cellpadding=0 cellspacing=0>
  <tr><td style='font-size:8pt;'> <font color=#808080>" . $pubDate . " 작성 <font color=#808080>| " . $category . "</font> <font color=#808080>| " . $description_len . "byte</font></font></td><td align=right style=\"font-family:Gulim;font-size:8pt;\" nowrap> </td></tr>
  </table>
</td></tr>
</table>
<table id=\"desc_9612007\" width=100% border=0 cellpadding=0 cellspacing=0>
<tr><td style='padding:6 2 0 2;line-height:14pt;' class=description>" . $description . "</td></tr>
<tr><td height=10></td></tr>
</table>
<table width=100% border=0 cellpadding=0 cellspacing=0><tr><td height=12></td></tr></table>
          ";
        }
      }
    }
  }
}

?>
</body>
</html>
<?php

$save_text = ob_get_contents();
ob_end_clean();

//캐쉬파일로 저장
$fp = @fopen($cashe_file, 'w');

if (empty($fp)) {

  echo "캐쉬 디렉토리의 퍼미션을 확인하세요";
  exit;
}

@fwrite($fp, $save_text);
@fclose($fp);
@chmod($cashe_file, 0777);

//출력
echo $save_text;

?>  

|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
16-06-11 조회 3,083
16-02-15 조회 3,318
16-02-02 조회 2,980
16-01-25 조회 2,596
16-01-18 조회 2,699
16-01-08 조회 2,616
16-01-07 조회 2,622
16-01-05 조회 2,657
16-01-05 조회 2,957
16-01-05 조회 2,933
16-01-05 조회 2,810
16-01-04 조회 2,673
16-01-04 조회 2,679
16-01-04 조회 2,625
16-01-04 조회 2,540
15-12-30 조회 2,895
15-12-24 조회 2,703
15-12-24 조회 2,699
15-12-24 조회 2,725
15-12-24 조회 2,682
15-12-23 조회 2,670
15-12-16 조회 2,765
15-12-15 조회 2,826
15-12-11 조회 2,954
15-12-10 조회 2,817
15-11-09 조회 2,797
15-11-09 조회 3,019
15-10-06 조회 3,355
15-10-02 조회 3,131
15-05-29 조회 4,465
15-02-02 조회 4,443
15-01-18 조회 4,434
14-10-25 조회 8,384
14-10-25 조회 5,166
14-10-22 조회 7,171
14-10-22 조회 4,870
14-10-22 조회 4,827
14-10-18 조회 5,691
14-10-17 조회 6,070
14-10-17 조회 5,451
14-10-17 조회 8,984
14-10-17 조회 6,466
14-10-13 조회 4,392
14-10-13 조회 4,490
14-10-07 조회 6,167
14-09-24 조회 3,937
14-09-23 조회 3,997
14-09-22 조회 4,911
14-09-22 조회 6,138
14-09-22 조회 4,107
14-09-22 조회 3,776
14-09-21 조회 4,399
14-09-21 조회 3,891
14-09-20 조회 3,892
14-09-20 조회 3,791
14-09-20 조회 3,971
14-09-19 조회 3,898
14-09-19 조회 4,059
14-09-19 조회 3,949
14-09-19 조회 4,322
14-09-19 조회 3,966
14-09-19 조회 3,893
14-09-19 조회 4,178
14-09-19 조회 3,914
14-09-19 조회 3,961
14-09-19 조회 3,944
14-09-18 조회 4,020
14-09-18 조회 3,980
14-09-18 조회 4,248
14-09-18 조회 4,220
14-09-18 조회 4,225
14-09-18 조회 4,926
14-09-18 조회 5,474
14-09-18 조회 5,364
14-09-18 조회 4,171
14-09-18 조회 4,661
14-09-18 조회 4,274
14-08-30 조회 5,542
14-08-06 조회 6,026
14-08-06 조회 5,640
14-08-03 조회 5,278
14-06-12 조회 5,548
14-05-11 조회 3,735
14-05-11 조회 4,501
14-05-11 조회 4,598
14-05-09 조회 1.3만
14-05-01 조회 5,194
14-03-30 조회 4,404
14-03-23 조회 8,028
14-02-12 조회 3,906
13-10-29 조회 7,865
13-10-28 조회 8,692
13-09-29 조회 6,660
13-09-29 조회 4,288
13-07-23 조회 5,162
13-07-23 조회 1.2만
13-07-14 조회 4,694
13-07-14 조회 5,082
13-07-14 조회 6,043
13-07-14 조회 5,325