<?php
require_once('PHPUniversalFeedParser/class/FeedParser.php');
$parser = new FeedParser();
$parser->parse('http://localhost/PHPProject/RSS/RSS.xml');
$channels = $parser->getChannels();
$items = $parser->getItems();
echo $channels['title'];
?>
XML文件:(http://localhost/PHPProject/RSS/RSS.xml) <?xml version="1.0" encoding="UTF-8" ?>
- <rss version="2.0">
- <channel>
<title>W3School Home Page</title>
<link>http://www.w3school.com.cn</link>
<description>Free web building tutorials</description>
<category>Web development</category>
- <image>
<url>http://www.w3school.com.cn/images/logo.gif</url>
<title>W3School.com.cn</title>
<link>http://www.w3school.com.cn</link>
</image>
<language>zh-CN</language>
<cloud domain="www.w3school.com.cn" port="80" path="/RPC" registerProcedure="NotifyMe" protocol="xml-rpc" />
<copyright>2006 w3school.com.cn. All rights reserved.</copyright>
- <item>
<title>RSS Tutorial</title>
<link>http://www.w3school.com/cn/rss</link>
<description>New RSS tutorial on W3School</description>
<author>[email protected]</author>
<comments>http://www.w3school.com.cn/comments</comments>
<enclosure url="http://www.w3school.com.cn/rss/rss.mp3" length="5000" type="audio/mpeg" />
</item>
</channel>
</rss>
为什么运行php文件却显示:
Notice: Undefined offset: -1 in D:\php5\includes\PHPUniversalFeedParser\class\FeedParser.php on line 345
Sorry! cannot detect the feed version.太奇怪了我在网上下载的文件示例也是这样用的:<?php
include('FeedParser.php');
$Parser = new FeedParser();$Parser->parse('http://www.sitepoint.com/rss.php');$channels = $Parser->getChannels();
$items = $Parser->getItems();
?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Testing the PHP Universal Feed Parser</title>
<style type="text/css">
body{
padding: 0px;
margin: 50px 150px;
border: 1px solid #ddd;
font-family: verdana, arial;
}
h1#title {
background-color: #eee;
border-bottom : 1px solid #ddd;
margin: 0px 0px 15px;
padding:10px;
text-align: center;
}
h1#title a{
font-size: 18px;
}
p, a{
padding: 5px;
margin: 5px;
font-size: 12px;
}
p#description{
font-size: 13px;
font-weight: bold;
}
p.feed-description{
border-bottom : 1px solid #ddd;
}
p#info{
background-color:#EDF001;
color: 1px solid #f6afab;
padding: 5px;
text-align: center;
color: #444;
}
</style>
</head>
<body>
<h1 id="title"><a href="<?php echo $channels['LINK']; ?>"><?php echo $channels['TITLE']; ?></a></h1>
<p id="description"><?php echo $channels['DESCRIPTION']; ?> </p>
<?php foreach($items as $item): ?>
<a class="feed-title" href="<?php echo $item['LINK']; ?>"><?php echo $item['TITLE']; ?></a>
<p class="feed-description"><?php echo $item['DESCRIPTION']; ?></p>
<?php endforeach;?>
<p id='info'>
This page is an example of using
<a href="http://www.ajaxray.com/blog/2008/05/02/php-universal-feed-parser-lightweight-php-class-for-parsing-rss-and-atom-feeds/">
PHP Universal Feed Parser
</a>.
</p>
</body>
</html>
下载网址:http://www.phpclasses.org/package/4548-PHP-Parse-RSS-and-ATOM-feeds.html#download
Sorry! cannot detect the feed version.在345行发生异常,无法检测到版本,怎么回事,去345行看看,是如何检测版本的,是在xml中查找吗?搞清楚后亲自去找一下看行段名称都存在不