Hi guys,
I am using a load_content.php file to grab an external rss feed, and the output of that file is a xml format (Content-type: text/xml) and it looks like an xml file when i view it on the browser.
Then I have feed.php on which I try to do this:
$rss = new DOMDocument('1.0', 'iso-8859-1');
$rss->load('load_content.php');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
);
array_push($feed, $item);
}
$limit = 8;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
$date = date('l F d, Y', strtotime($feed[$x]['date']));
echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
echo '<small><em>Posted on '.$date.'</em></small></p>';
echo '<p>'.$description.'</p>';
}
?>
I always get an error
Warning: DOMDocument::load() [domdocument.load]: xmlParsePI : no target name in /home/admin/sites/domain.com/htdocs/load_content.php, line: 1 in /home/admin/sites/domain.com/htdocs/feed.php on line 8
Notice: Undefined offset: 0 in /home/admin/sites/domain.com/htdocs/feed.php on line 21
The thing is, if i create the xml file manually and not retrieve the data from the php file, and I do this,
$rss->load('file.xml');
it works flawlessly. But it doesn’t help because I need to grab the rss feed using php at load_content.php
Anyone could help?