<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Open Source Web &#187; banners</title>
	<atom:link href="http://www.open-source-web.com/tag/banners/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.open-source-web.com</link>
	<description>Your open source for Development and Design</description>
	<lastBuildDate>Sun, 08 Jan 2012 10:21:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Random Banner with PHP</title>
		<link>http://www.open-source-web.com/php/random-banner-with-php/</link>
		<comments>http://www.open-source-web.com/php/random-banner-with-php/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 22:26:15 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[banners]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=103</guid>
		<description><![CDATA[This is a quick tutorial which shows how easy it is to make a random banner script with PHP. We will use a PHP array of images which is populated by a given directory and select a random index from the array to be the banner. For this example I have chosen to list the [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick tutorial which shows how easy it is to make a random banner script with PHP. We will use a PHP array of images which is populated by a given directory and select a random index from the array to be the banner.</p>
<p>For this example I have chosen to list the files from a directory as this will keep the script fairly dynamic without the need of a database. The script could be easily modified to use a database but we can come back to that later on if we need to.</p>
<p>To start off all you will need is a folder with several banners and a page to display them on.</p>
<p>$dir will be the directory you have created to grab the images from, it is important to make sure this folder only contains banners.<br />
$banners will be the array of images found in the given folder.</p>
<pre class="php" name="code">

 $banners = array();
  $dir = 'res/banners/';
  if ($handle = opendir($dir)) {
  while (false !== ($file = readdir($handle))) {
  if($file != &quot;.&quot; &amp;&amp; $file != &quot;..&quot;){
  $banners[] = $file;
  }
  }
  closedir($handle);
  }

  $rand = array_rand($banners,1);
  echo &quot;&lt;img src='&quot;.$dir.$banners[$rand].&quot;' alt='banner'/&gt;&quot;;   
</pre>
<p>The code above uses a few handy built in PHP functions:<br />
opendir()<br />
readdir()<br />
array_rand()<br />
print_r()</p>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/php/random-banner-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

