Classic ASP Active Server Pages Examples, code, tutorials, scriptsParse RSS - XML Feed with PHP for Javascript Slideshow (Zenphoto)

CURL, PHP, RSS or XML, Javascript Slideshow example uses Zenphoto Gallery RSS feed. This can be adapted to almost any javascript slideshow. NO flash, flash free!

I really like Zenphoto! I wanted to use the RSS feed that is produced by zenphoto as the data backend for a slideshow using zenphoto images that could be shown elsewhere on the site or on another site entirely. I did NOT want to have to use flash/SWF at all. The slideshow script is in the white table below (scroll down).

Note about zenphoto: The scripts automatically update the database with the names of new folders. If you use FrontPage or ExpressionWeb, this means that eventually, you'll end up with albums that are titled "_vti_cnf." The immediate way to deal with these is to login to the admin area and UNpublish those albums so they will not be publicly linked. If you attempt to delete them, FrontPage will re-create them and zenphoto wll add them again, so it is better just to UNpublish them.

The slideshow script has code in it to filter out those folders, in case the remote site that hosts the RSS feed is modified with FrontPage. However, I have written a short little PHP script to dynamically make those folder names non-public/unpublished by updating the `show` columns of the undesired records in the database to 0. I don't delete those records because zenphoto would simply re-create them. This is not as elegant as it would be to write a zenphoto extension, but it is quick and easy. At the very bottom of the zenphoto index.php file, paste in:

$con = mysql_connect("DBHOST","USERID","PASSWORD");
if (!$con)
die('Could not connect: ' . mysql_error());
mysql_select_db("zenphoto", $con);
mysql_query("UPDATE `zp_albums` SET `show` ='0' WHERE (INSTR( folder, '_vti_cnf' ) >0) AND `show`='1'");
$query = "SELECT `id` FROM `zp_albums` WHERE (INSTR( folder, '_vti_cnf' ) >0)";
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
$sRec = $row[0];
$rsImgUp="UPDATE `zp_images` SET `show` ='0' WHERE `albumid` = '".$sRec."' AND `show`='1'";
mysql_query($rsImgUp) or die ("Error in query: ".$rsImgUp);
//print "<br /><em>Updated!</em><br /><br />";


Another, perhaps more simple option is:

Go to the admin menu on the page right of the overview tab and click on the link "publish content" (schedule_content.php).

On the form that opens:

Publishing options
Publish albums by default UN-SELECT THIS

Make images visible by default UN-SELECT THIS


That option makes it so that new folders (and images) are not automatically, dynamically made public (published). This is a good option for FrontPage/ExpressionWeb users. WHY might you want to use both options? If someone else will be admininstrator of the photo gallery, they might change the settings. The PHP code is insurance for that.



<table><tr><!-->loader animation in background of cell-->
<td style="background-position: center; text-align: center; width: 300pxpx; background-image:url('ajax-loader.gif'); background-repeat:no-repeat">

<script language="javascript">

Random image slideshow- By Tyler Clarke (
For this script and more, visit -
PHP RSS/XML parser from
ajax-loader.gif from
This example using zenphoto rss at

var delay=3000 //set delay in miliseconds
var curindex=0

var randomimages=new Array()


$ch = curl_init("http://YOURURL/zenphoto/index.php?rss");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
$doc = new SimpleXmlElement($data, LIBXML_NOCDATA);


function parseRSS($xml)

//echo "<strong>".$xml->channel->title."</strong>";
$cnt = count($xml->channel->item);
for($i=0; $i<$cnt; $i++)
$url = $xml->channel->item[$i]->link;
$title = $xml->channel->item[$i]->title;
$desc = $xml->channel->item[$i]->description;

$pos = strpos($desc, '_vti_cnf'); //this is to filter out certain FrontPage/ExpressionWeb folders
if ($pos ===false) {
//echo " N ".$n;
$myPic = explode("src=",$desc,2);
$myPix = explode(" alt=",$myPic[1]);

$input = trim( preg_replace( '/\s+/', '', "randomimages[". ($n) ."]=$myPix[0]" ) );
$picSet= "$input\n";
//echo '<a href="'.$url.'">'.$title.'</a>'.$desc.'';

echo $picSet;


//this section for Atom formatted feeds
function parseAtom($xml)
echo "<strong>".$xml->author->name."</strong>";
$cnt = count($xml->entry);
for($i=0; $i<$cnt; $i++)
$urlAtt = $xml->entry->link[$i]->attributes();
$url = $urlAtt['href'];
$title = $xml->entry->title;
$desc = strip_tags($xml->entry->content);

echo '<a href="'.$url.'">'.$title.'</a>'.$desc.'';


var preload=new Array()

for (n=0;n<randomimages.length;n++)
preload[n]=new Image()

//Choose display with or without hyperlink:
//document.write('<a href=http://YOURDOTCOM/zenphoto/><img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*(randomimages.length))]+'"></a>')
document.write('<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*(randomimages.length))]+'">')

function rotateimage()

if (curindex==(tempindex=Math.floor(Math.random()*(randomimages.length)))){
curindex=curindex==0? 1 : curindex-1







Back to Site Menu
My favorite scripts site is