当前位置:编程学习 > php >>

利用PHP实现与ASP Banner组件相似的类

<?php
/*******************************************************
作者: 吴振亨 (Biz)--phpscript
E-mail:wuzhenheng@china.com
web: http://phpscript.osh.com.cn
文件名:AdRotator.class.php3                 
版权声明:                      

如果您使用了本文件,请给作者写一封E-mail   
如有问题欢迎与作者联系
谢谢您的关注!                     
********************************************************/

/*
广告条管理程序
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  
返回广告的链接字串
*/
function GetAdvertisement($adfile)
    {
    if(count($this->BannerData)==0)
        {
        $this->BannerData=$this->ReadAdFile($adfile);
        }
    $AdData=$this->BannerData;
     
    $uplimited=count($AdData);
     
    //随机产生一个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.=" <img border="".$this->Border;
        $LinkString.="" src="".$AdData[$id]["image"];
        $LinkString.="" width="".$this->Width;
        $LinkString.="" height="".$this->Height;
        $LinkString.="" >";
        $LinkString.="</a>";
         
        //echo $LinkString;
        return $LinkString;
    }
/*
private
读入文件的基本设置
*/
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":
  
补充:Web开发 , php ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,