Simple PHP ad banner / image rotator


/ Published in: PHP
Save to your folder(s)

Pull banner ad or image code from a given text file into an array and randomize the order. Banner/image codes in the file should be separated by tildes (~).


Copy this code and paste it in your HTML
  1. function initializeAds($file) {
  2. $fcontents = file_get_contents($file);
  3. $ad_array = explode("~",$fcontents);
  4. shuffle($ad_array);
  5.  
  6. return $ad_array;
  7. }
  8.  
  9. $ad_banners = initializeAds('ad_banners.txt');
  10.  
  11. echo $ad_banners[0]; // first randomly ordered banner
  12. echo $ad_banners[1]; // second randomly ordered banner, etc.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.