TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

March 29, 2024, 05:43:00 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,105
  • Total Topics: 21,213
  • Online today: 358
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 339
  • Total: 340
  • @rjen

RSS feed block question

Started by VladTepes, March 24, 2017, 05:29:32 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

VladTepes

OK well I grabbed said script as follows:

$rss = new DOMDocument();
$rss->load('http://www.motogp.com/en/news/rss');
$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 '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
echo '<small><em>Posted on '.$date.'</em></small></p>';
echo '<p>'.$description.'</p>';
}


but the actual feed has some super-odd characters in it (see attached).
Any ideas on why / a fix for this?

Secondly, how do I mod that script so it grabs images too?

Thanks.

lurkalot

#11
Might have to convert to UTF-8 to stop that from happening.  This will also give you a bit of future proofing, as The new SMF 2.1 is already UTF-8 as standard.

http://wiki.simplemachines.org/smf/UTF-8_Readme

Backup database etc before doing anything.

Actually my testsite was displaying that MotoGP feed same as yours, so I just converted it to UTF-8 all seems fine now.http://cctestsite.info/forums/index.php