Discussion:
php rss grabber strange characters
David Mehler
2014-04-13 23:17:17 UTC
Permalink
Hello,

Can someone take a look at the below code and tell me what it's problem is?

What it's suppose to do is grab three news items from wordpress's rss
feed. This it does. The issue is in the output I get strange
characters a circumflexes I'd like to know why and if I can fix this?

Here's my code:

<?php

$rss = new DOMDocument();
$rss->load('http://wordpress.org/news/feed/');

$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(' & ', ' &amp; ', $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>';
}
?>

Thanks.
Dave.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz Saleh
2014-04-13 23:30:06 UTC
Permalink
Post by David Mehler
Hello,
Can someone take a look at the below code and tell me what it's problem is?
What it's suppose to do is grab three news items from wordpress's rss
feed. This it does. The issue is in the output I get strange
characters a circumflexes I'd like to know why and if I can fix this?
<?php
$rss = new DOMDocument();
$rss->load('http://wordpress.org/news/feed/');
$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(' & ', ' &amp; ', $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>';
}
?>
Thanks.
Dave.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Make sure that the page you are displaying this on is UTF8 (which is what
the feed is based on).

Loading...