Using PHP to implement classes similar to ASP banner components

Source: Internet
Author: User
Tags count implement mail rand
<?php
/*******************************************************
Author: Wu Zhenhen (Biz)--phpscript
E-mail:wuzhenheng@china.com
web:http://phpscript.osh.com.cn
FileName: AdRotator.class.php3
Copyright Notice:

If you use this document, please write an e-mail to the author
Please contact the author if you have any questions
Thank you for your attention!
********************************************************/

/*
Advertising Bar 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
Returns the link string for the advertisement
*/
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 = "<a href=" ". $this->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. = "</a>";

Echo $LinkString;
return $LinkString;
}
/*
Private
Basic settings for reading into 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 "<br>"; 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
Advertising settings 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 advertising component
* Indicates the setting, others are the picture's setting #: Indicates a comment

----Use-----
$banner =new AdRotator ();
echo $banner->getadvertisement ("./banner.txt");
echo $banner->getadvertisement ("./banner.txt");
echo $banner->getadvertisement ("./banner.txt");
*/
?>

"This article copyright belongs to the author and the Osso net jointly owns, if needs to reprint, please indicate the author and the origin"


Related Article

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.