I'm trying to create myself a news page using PHP. However, I ran into a little bit of a roadblock. I want each post to be separated, to only have 5 posts at a time loaded, and for the HTML to be preserved. I got the first two, but the third is becoming a problem.
I've tried everything I can. I don't exactly know how each function is interacting with each other, so I always break something when trying to add something new. I tried using saveHTML() in here, but no matter where I place it, it either does nothing or breaks something.
All I want is for the post's content to preserve the HTML, some posts have unordered lists, and some have links.
By the way, here is the code:
<?php
$rss = new DOMDocument();
$rss->load('http://screenbones.com/news.xml');
$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 = 5;
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 '<article>';
echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
echo '<small><em>Posted on '.$date.'</em></small></p>';
echo $description;
echo '</article>';
}
?>
Aucun commentaire:
Enregistrer un commentaire