[펌] PHP로 된 RSS 리더 소스

<html>
<head>
<title>SAX Demonstration</title>
<META HTTP-EQUIV=’Content-type’ CONTENT=’text/html; charset=euc-kr’>
</head>
<body>
<h1>RSS 리더기</h1>

<?php

$file = “http://blog.naver.com/post/postXMLList.jsp?blogId=suvisor”;

$currentTag = “”;
$currentAttribs = “”;

function startElement($parser, $name, $attribs)
{
global $currentTag, $currentAttribs;
$currentTag = $name;

$currentAttribs = $attribs;
switch ($name) {

default:
echo(“startElement : $name<br>”);
break;
}
}

function endElement($parser, $name)
{
global $currentTag;
switch ($name) {
default:
echo(“<br>$name endElement<br>”);
break;
}
$currentTag = “”;
$currentAttribs = “”;
}

function characterData($parser, $data)
{
global $currentTag;
switch ($currentTag) {
case “link”:
echo(“<a href=”$data”>$data</a>n”);
break;
case “title”:
echo(“title : $data”);
break;
default:
echo($data);
break;
}
}

$xmlParser = xml_parser_create();

$caseFold = xml_parser_get_option($xmlParser,
XML_OPTION_CASE_FOLDING);

$targetEncoding = xml_parser_get_option($xmlParser,
XML_OPTION_TARGET_ENCODING);

if ($caseFold == 1) {
xml_parser_set_option($xmlParser, XML_OPTION_CASE_FOLDING, false);
}

xml_set_element_handler($xmlParser, “startElement”, “endElement”);
xml_set_character_data_handler($xmlParser, “characterData”);

if (!($fp = fopen($file, “r”))) {
die(“Cannot open XML data file: $file”);
}

while ($data = fread($fp, 4096)) {
if (!xml_parse($xmlParser, $data, feof($fp))) {
die(sprintf(“XML error: %s at line %d”,
xml_error_string(xml_get_error_code($xmlParser)),
xml_get_current_line_number($xmlParser)));
xml_parser_free($xmlParser);
}
}
xml_parser_free($xmlParser);
?>
</table>
</body>
</html>

답글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다.