我试图用php设置一个rss阅读器。我从w3schools(http://www.w3schools.com/php/php_ajax_rss_reader.asp)
获得了这段代码这是getrss.php页面
<?php
//get the q parameter from URL
$q=$_GET["q"];
//find out which feed was selected
if($q=="Google") {$xml=("http://news.google.com/news?ned=us&topic=h&output=rss");}
else if($q=="NBC") {$xml=("http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml");}
$xmlDoc=new DOMDocument();
$xmlDoc->load($xml);
//get elements from "<channel>"
$channel=$xmlDoc->getElementsByTagName('channel')->item(0);
$channel_title=$channel->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
$channel_link=$channel->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
$channel_desc=$channel->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;
//output elements from "<channel>"
echo("<p><a href='".$channel_link."'>".$channel_title."</a>");
echo("<br>");
echo($channel_desc."</p>");
//get and output "<item>" elements
$x=$xmlDoc->getElementsByTagName('item');
for ($i=0; $i<=2; $i++) {
$item_title=$x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
$item_link=$x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
$item_desc=$x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;
echo ("<p><a href='".$item_link."'>".$item_title."</a>");
echo ("<br>");
echo ($item_desc."</p>");
}
?>
这是Javascript
<script>
function showRSS(str) {
if (str.length==0) {
document.getElementById("rssOutput").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("rssOutput").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getrss.php?q="+str,true);
xmlhttp.send();
}
</script>
这是HTML
<form>
<select onchange="showRSS(this.value)">
<option value="">Select an RSS-feed:</option>
<option value="Google">Google News</option>
<option value="NBC">NBC News</option>
</select>
</form>
<br>
<div id="rssOutput">RSS-feed will be listed here...</div>
<小时/> 现在由于某种原因,我在我的页面上得到错误,如...
警告:DOMDocument :: load(rss.msnbc.msn.com/id/3032091/device/rss/rss.xml):无法打开流:连接尝试失败,因为连接方没有正确响应一段时间,或建立的连接失败,因为连接的主机无法响应。在第10行的.. \ test \ getrss.php
警告:DOMDocument :: load():I / O警告:无法加载外部实体&#34; rss.msnbc.msn.com/id/3032091/device/rss/rss.xml"在第10行的.. \ test \ getrss.php
致命错误:第13行的E:\ webroot \ IIS_Intranet \ test \ getrss.php超出了30秒的最长执行时间
我已经试着抬头看看我如何纠正这个但是没有成功