Location: PHPKode > scripts > PHP Ad Text > phpadtext.php
<?php
/*==============================================
PHP ADTEXT v1.0b by Brian Vogt
Copyright 2006 By Brian Vogt
http://softwarebybrian.com

This script is FREE.

You may use this script for commercial
or personal use, and may modify and
re-distribute it under the terms of the
GNU General Public License.  This notice
MUST remain in this same location at the
top of the script, and MUST remain intact
and unmodified.

You may view the license details here:
http://www.gnu.org/copyleft/gpl.html

ABOUT:
PHP ADTEXT is a VERY Simple Script to display
random ads from a list of links contained in
a text file.  You can use it multiple places 
and with multiple categories of links by 
using multiple text files and multiple copies
of the script OR by overriding a variable 
before each include (see below).

Please send comments to:
hide@address.com

Feel free to send any updates you've made to 
the script and I can upload them to the site
to replace this file or as a separate file.

___________________________________________

usage instructions:
___________________________________________

1. Put a list of your own hyperlinks into 
the ads1.txt file, or whatever file you 
choose to use.  Upload both files to a spot
on your webserver.

2. To use you do the following:

	A. override any varilables 
	
	$title -- title to display with ads, if any
	$adsfile -- the file that contains the ads
	$maxads -- maximum number of ads to display
	$spacing -- spacing between each link (how
	 many of the $spacer below to place)
	$spacer -- what separates the ads ...
	 usually <br> or &nbsp; but could be
	 something else
	$titlespacing -- spc count between title 
	and ads
	
	B. include the file in the spot where you 
	want the ads to show up.
	
	<? include("phpadtext.php");?>  or 
	something similar

	
================================================*/


//-----defaults-----//
if (!isset($title)){ $title = "<b>Sponsored Links:</b>";} // set to "" to exclude title.
if (!isset($adsfile)){ $adsfile = "ads1.txt";} // file containing one hyperlink per line
if (!isset($maxads)) { $maxads = 4; } //max ads to show
if (!isset($spacing)){ $spacing = 3; } //spacing count between ads
if (!isset($spacer)) { $spacer = "&nbsp;"; }  //set to <br> for a vertical list, to &nbsp; for a space
if (!isset($titlespacing)){ $titlespacing = 2; } //spacing count between title and ads


//==============================SCRIPT STARTS HERE
if (file_exists($adsfile))
{
	$ads = array_filter(file($adsfile)); // get the list from the file
	
	if (count($ads) > 0 && $maxads > 0) //only go on if the ads file isn't empty, and maxads has is > 0
	{
		if (count($ads) > $maxads) // there are plent of ads to choose from, so get a random selection
		{
			
			if ($title != "")
			{
				echo "$title" . str_repeat($spacer,$titlespacing);
			}
			
			$selectedkeys = array_rand($ads,$maxads); //get a mixed random list of keys from the ads	
			
			if ($maxads > 1)
			{			
				//print each link in the shuffled order
				foreach ($selectedkeys as $key)
				{
					if ($ads[$key] != "")
					{
						print "$ads[$key]" . str_repeat($spacer,$spacing);
				    }
				}
			}
			else // maxads is "1" just get the one link
			{
				print "$ads[$selectedkeys]" . str_repeat($spacer,$spacing);
			}
		
		} 
		else //if maxads is greater than ads, just print whatever is in ads
		{
			if ($title != "")
			{
				echo "$title" . str_repeat($spacer,$titlespacing);
			}
			
			if ($maxads > 1)
			{
				foreach ($ads as $ad)
				{
					if ($ad != "")
					{
						print "$ad" . str_repeat($spacer,$spacing);
					}
				}
			}
			else 
			{
				print "$ads[0]" . str_repeat($spacer,$spacing);
			}
		}//end if count(ads) > maxads
	
	}//end if count and max ads > 0
	
}
else
{
	//nothing to do here.  replace with banner or alternate ad code if you want!
}


?>
Return current item: PHP Ad Text