RSS

Simple Random Advert Rotator Tutorial - PHP

Wed, Nov 5, 2008

PHP

In this tutorial Im going to show you how to make a random advert rotator.

The way we are going to do it is through an array to define our adverts then use an array function to shuffle the array.

So the first thing we need to create the array…

$adverts=array('<a href="http://www.website.com"><img src="image.gif" alt="" /></a>'=&gt;'1','<a href="http://www.website.com"><img src="image.gif" alt="" /></a>'=&gt;'2','<a href="http://www.website.com"><img src="image.gif" alt="" /></a>'=&gt;'3');

Now we have done that we need to make the array show up randomly. We do that using a function called array_rand ( ).

print_r(array_rand($adverts,1));

Then thats everything. Heres a demo that uses my three websites as adverts.

Full Code:

<?php
$adverts=array('<a href="http://www.website.com"><img src="image.gif" alt="" /></a>'=&gt;'1','<a href="http://www.website.com"><img src="image.gif" alt="" /></a>'=&gt;'2','<a href="http://www.website.com"><img src="image.gif" alt="" /></a>'=&gt;'3');
print_r(array_rand($adverts,1));
?>
Rating: 10.0/10 (5 votes cast)
Share and Enjoy:
  • Digg
  • Google
  • Technorati
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Furl
  • Live
  • Reddit
  • Spurl

  • Subscribe
    • XML
    • Google Reader or Homepage
    • Add to My Yahoo!
    • Subscribe with Bloglines
    • Subscribe in NewsGator Online
    • BittyBrowser
    • Add to My AOL
    • Convert RSS to PDF
    • Subscribe in Rojo
    • Subscribe in FeedLounge
    • Subscribe with Pluck RSS reader
    • Solosub
    • MultiRSS
    • R|Mail
    • Rss fwd
    • Blogarithm
    • Eskobo
    • gritwire
    • BotABlog
    • Simpify!
    • Add to Technorati Favorites!
    • Add to netvibes
    • Add this site to your Protopage
    • Subscribe in NewsAlloy
    • Subscribe in myEarthlink
    • Add to your phone
    • Get RSS Buttons

, , , , ,



This post was written by:

admin - who has written 41 posts on Unreal Media.


Contact the author

1 Comments For This Post

  1. Briefe Schreiben Says:

    Hi! Your Post “” is very interesting for me. Unfortunately my written English is not so good so I write in German: Dir, meinem liebsten, geh

    Rating: 0.0/5 (0 votes cast)

Leave a Reply