0

I need help building a script to pull a random image from an rss feed and echo it out.... I just need something that searches the rss feed and pulls a random image from it! Thanks


I was trying to work with this script but it only pulls text also the images are stored in <content:encoded> tags.... Any help would be much appreciated..

<?
function load_xml_feed($location)
{
global $value1;
$feedXml = simplexml_load_file($location);

$i= '1';
foreach ($feedXml->channel->item as $article)
{
$title[$i] = (string)$article->title;
$link[$i] = (string)$article->link;
$description[$i] = (string)$article->description;

$i++;

}
$randnumber = rand(2, $i);
$link = trim($link[$randnumber]);
$title = trim($title[$randnumber]);
$description = trim($description[$randnumber]);
$title = iconv("UTF-8", "ISO-8859-1", $title);
$description = iconv("UTF-8", "ISO-8859-1", $description);
$value1 = array($title,$link,$description);
return $value1;
}

$rss = 'xxx';
load_xml_feed($rss);
$link = $value1[1];
$title = $value1[0];
$description = $value1[2];

echo $link;
echo $title;
echo $description; 
?>
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by cereal
0

Build an array from the XML feed and then use shuffle():

<?php
$a = array(
	'a' => array('a1','a2','a3'),
	'b' => array('b1','b2','b3'),
	'c' => array('c1','c2','c3'),
	'd' => array('d1','d2','d3'),
	'e' => array('e1','e2','e3')
);
shuffle($a);
echo $a[0][0]; # will print randomly a1, b1, c1, d1, e1
echo $a[0][1]; # will print randomly a2, b2, c2, d2, e2 ...
?>

bye :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.