AD text

  AD text
<?
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!
}


?>