I wrote a simple XML parser that takes a feedburner feed and loops out a few titles and permalinks.
As a failsafe to keep the whole page from breaking if the feed is down or something I wanted to add an if statement using file_exists. But it keeps returning false even though the url is correct.
I have limited PHP knowledge. Am I doing this right? Is there a better way to do this?
<?php
$request_url = "http://feeds.feedburner.com/feed";
if(file_exists($request_url)) {
$xml = simplexml_load_file($request_url) or die("feed not loading");
for($i=0;$i<5;$i++) {
$title = $xml->channel->item[$i]->title;
$link = $xml->channel->item[$i]->link;
echo"<a href=".'"'.$link.'"'.">";
echo($title);
echo"</a><br />";
};
} else {
echo "Cannot locate blog feed.";
}
?>
<?php
$request_url = "http://feeds.feedburner.com/feed";
if(file_exists($request_url)) {
$xml = simplexml_load_file($request_url) or die("feed not loading");
for($i=0;$i<5;$i++) {
$title = $xml->channel->item[$i]->title;
$link = $xml->channel->item[$i]->link;
echo"<a href=".'"'.$link.'"'.">";
echo($title);
echo"</a><br />";
};
} else {
echo "Cannot locate blog feed.";
}
?>
btw, this editor is giving me grief. . . I apologize for the repeated code. It won’t let me remove it.