Banner online production using PHP to implement classes similar to ASP banner components

Source: Internet
Author: User
/*******************************************************
Author: Wu Zhenhen (Biz)--phpscript
E-mail:wuzhenheng@china.com
web:http://phpscript.osh.com.cn
File name: AdRotator.class.php3
Copyright Notice:
If you use this file, please write an e-mail to the author
If you have questions, please contact the author.
Thank you for your attention!
********************************************************/
/*
AD Strip Management Program
Public method
GetAdvertisement ($adfile)
Parameters
target=
Width=
height=
Border=
redirect=
*/
Class AdRotator {
var $Target = "_blank";
var $Width = "460";
var $Height = "60";
var $Border = 0;
var $Redirect = "";
var $BannerData =array ();
var $RandTemp = 1;
function AdRotator ()
{
}
/*
Public
Return a link string for an ad
*/
function GetAdvertisement ($adfile)
{
if (count ($this->bannerdata) ==0)
{
$this->bannerdata= $this->readadfile ($adfile);
}
$AdData = $this->bannerdata;
$uplimited =count ($AdData);
Randomly generate an ID
Srand (Double) microtime () *1000000000000000000);
$id = @rand (1, $uplimited);
while ($this->randtemp== $id)
{
Srand (Double) microtime () *1000000000000000000);
$id = @rand (1,count ($AdData));
$id = @rand (1, $uplimited);
}
$this->randtemp= $id;
echo $id;
echo count ($AdData);
echo $AdData [5]["image"];

$LinkString = "Redirect;
$LinkString. = "Url=". $AdData [$id] [url];
$LinkString. = "Target=" ". $this->target;
$LinkString. = "Title=" ". $AdData [$id] [Title];
$LinkString. = ">";
$LinkString. = "Border;
$LinkString. = "Src=" ". $AdData [$id] [image];
$LinkString. = "Width=" ". $this->width;
$LinkString. = "Height=" ". $this->height;
$LinkString. = ">";
$LinkString. = "";
Echo $LinkString;
return $LinkString;
}
/*
Private
Basic settings for read-in Files
*/
function Readadfile ($adfile)
{
$FP =fopen ($adfile, "R");
while ($buffer = @fgets ($FP, 1024))
{
if (!eregi ("#", $buffer))
{
if (eregi ("^*", $buffer))
{
$switchto = "Off";
}
$SetTemp =split ("=", $buffer);
if ($switchto = = "")
{
switch ($SetTemp [0])
{
Case "REDIRECT":
$this->redirect= $SetTemp [1];
Break
Case "WIDTH":
$this->width= $SetTemp [1];
Break
Case "HEIGHT":
$this->height= $SetTemp [1];
Break
Case "BORDER":
$this->border= $SetTemp [1];
Break
Case "TARGET":
$this->target= $SetTemp [1];
Break
}
}
Else
{
switch ($SetTemp [0])
{
Case "image":
$i + +;
$BannerData [$i] [image]]= $SetTemp [1];
echo "
echo $buffer; echo $SetTemp [1];
echo $BannerData [$i] [image];
Break
Case "url":
$BannerData [$i] [url]]= $SetTemp [1];
Break
Case "title":
$BannerData [$i] ["title"]= $SetTemp [1];
Break
Case ' rate ':
$BannerData [$i] [rate]]= $SetTemp [1];
Break
}//end of Switch
}//end of If ($switch)
}//end of If (#)
}//end of While
return $BannerData;
}//end of function
}//end of Class
/*
How to use
Ad setup file writing format Banner.txt
------Start---
Redirect=./adredir.asp
width=468
Height=60
Border=0
*
#注释
#某某公司广告1
Image=. /banner/1.gif
Url=http://www.asps0ite.com1
Title=one
Rate=30
----End-----
Description
Similar to ASP's ad components
* Indicates settings, other settings for the picture #: Indicates comments
----Use-----
$banner =new AdRotator ();
echo $banner->getadvertisement ("./banner.txt");
echo $banner->getadvertisement ("./banner.txt");
echo $banner->getadvertisement ("./banner.txt");
*/
?>
"The copyright of this article is owned by the author and house Orso near net, if need to reprint, please specify the author and source"

The above describes the banner online production using PHP to achieve and ASP banner components similar to the class, including the content of the banner online production, I hope to be interested in PHP tutorial friends helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.