<? // PHP RSS Reader v0.1 // Code By Jusun at 2007-01-25 // 라이센스 : FREE ... // Modify by 카멜롯™
// RSS_reader("가져올갯수","제목글자수","RSS주소","인코딩");
// RSS 읽어오기 function getRSS($url){ $url_parsed = parse_url($url); $host = $url_parsed["host"]; $port = $url_parsed["port"]; if($port==0) $port = 80; $path = $url_parsed["path"];
if(empty($path)) $path = "/"; if(empty($host)) return false;
if($url_parsed["query"] != "") $path .= "?".$url_parsed["query"]; $out = "GET ".$path." HTTP/1.0\r\nHost: ".$host."\r\n\r\n"; $fp = @fsockopen($host, $port, $errno, $errstr, 30); usleep(50); if($fp) { socket_set_timeout($fp, 30); fwrite($fp, $out); $body = false; while(!feof($fp)) { $buffer = fgets($fp, 128); if($body) $content .= $buffer; if($buffer=="\r\n") $body = true; } fclose($fp); }else { return false; } return $content; }
// 내용만 뽑아내기 function parseTag($tag,$value){ $value = explode("</".$tag.">",$value); $value = explode("<".$tag.">",$value[0]); return $value[1]; }
//한글 자르기 function hstrCut($msg,$cut_size,$end_str = "...") { if( (strlen($msg) > $cut_size) & ($cut_size > 0) ) { $msg = substr($msg,0,$cut_size); $msg = preg_replace("/(([\\x80-\\xFE].)*)[\\x80-\\xFE]?$/","\\1",$msg); $msg .= $end_str; } return $msg; }
// 보여지는 부분 function RSS_reader($count,$cutstr,$url,$encode = "EUC-KR"){ $channel = parseTag("channel",getRSS($url)); // 인코딩 변환 if($encode == "UTF-8"){ $channel = iconv("UTF-8","EUC-KR",$channel); } $channel = str_replace("</item>","",$channel); $item = explode("<item>",$channel); // 제목 처리 $siteTitle = parseTag("title",$item[0]); $siteLink = parseTag("link",$item[0]); $siteDescription = parseTag("description",$item[0]); //제목 출력 //$html = "[<a href=\"$siteLink\" target=\"_blank\">$siteTitle</a>]<br />"; echo "[<a href=\"$siteLink\" target=\"_blank\" class=\"AutoLinkType_red\">$siteTitle</a>]<br />";
//각 게시물 제목 처리 for($i=1;$i<=$count;$i++){ if(!isset($item["$i"])) break; //제목 가져오기 $title = hstrCut(parseTag("title",$item[$i]),$cutstr); //링크 가져오기 $link = parseTag("link",$item[$i]); //내용 가져오기 $description = parseTag("description",$item[0]);
$html .= "<a href=\"$link\" target=\"_blank\" class=\"AutoLinkType_red\">$title</a> <br />\n"; echo "· <a href=\"$link\" target=\"_blank\" class=\"AutoLinkType_blue\">$title</a> <br />\n"; }
// 출력 // echo $html; } ?> <html> <head> <title>RSS 리더기(RSS READER) - RSS 2.0</title> <style> A {font-size:13px;} A.AutoLinkType_red:link {font-family: '맑은 고딕', Dotum, Verdana;text-decoration:none;color:#D8442C;border-bottom:2px solid #E78B29;} A.AutoLinkType_red:visited {font-family: '맑은 고딕', Dotum, Verdana;text-decoration:none;color:#D8442C;border-bottom:2px solid #E78B29;} A.AutoLinkType_red:active {font-family: '맑은 고딕', Dotum, Verdana;text-decoration:none;color:#D8442C;border-bottom:2px solid #E78B29;} A.AutoLinkType_red:hover {font-family: '맑은 고딕', Dotum, Verdana;text-decoration:none;color:#A9250F;border-bottom:2px solid #DD7611;position:relative; top:1; left:-1;}
A.AutoLinkType_blue:link {font-family: '맑은 고딕', Dotum, Verdana;text-decoration:none;color:#2A61A4;border-bottom:2px solid #37AFCD;} A.AutoLinkType_blue:visited {font-family: '맑은 고딕', Dotum, Verdana;text-decoration:none;color:#2A61A4;border-bottom:2px solid #37AFCD;} A.AutoLinkType_blue:active {font-family: '맑은 고딕', Dotum, Verdana;text-decoration:none;color:#2A61A4;border-bottom:2px solid #37AFCD;} A.AutoLinkType_blue:hover {font-family: '맑은 고딕', Dotum, Verdana;text-decoration:none;color:#144684;border-bottom:2px solid #3796CD;position:relative; top:1; left:-1;}
A.AutoLinkType_green:link {font-family: '맑은 고딕', Dotum, Verdana;text-decoration:none;color:#368E36;border-bottom:2px solid #76BD31;} A.AutoLinkType_green:visited {font-family: '맑은 고딕', Dotum, Verdana;text-decoration:none;color:#368E36;border-bottom:2px solid #76BD31;} A.AutoLinkType_green:active {font-family: '맑은 고딕', Dotum, Verdana;text-decoration:none;color:#368E36;border-bottom:2px solid #76BD31;} A.AutoLinkType_green:hover {font-family: '맑은 고딕', Dotum, Verdana;text-decoration:none;color:#136F13;border-bottom:2px solid #5FA90F;position:relative; top:1; left:-1;} </style> </head> <body>
<?=RSS_reader("30","100","http://notice.tistory.com/rss","EUC-KR");?>
</body> </html> |