您好,欢迎访问一九零五行业门户网

banner在线制作 利用PHP实现与ASP Banner组件相似的类

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= 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
读入文件的基本设置
*/
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
/*
使用方法
广告设置文件书写格式banner.txt
------开始---
redirect=./adredir.asp
width=468
height=60
border=0
*
#注释
#某某公司广告1
image=../banner/1.gif
url=http://www.asps0ite.com1
title=one
rate=30
----结束-----
说明:
与asp的广告组件相仿
*表示设置,其他为图片的设置 #:表示注释
----使用-----
$banner=new adrotator();
echo $banner->getadvertisement(./banner.txt);
echo $banner->getadvertisement(./banner.txt);
echo $banner->getadvertisement(./banner.txt);
*/
?>  
【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】
以上就介绍了banner在线制作 利用php实现与asp banner组件相似的类,包括了banner在线制作方面的内容,希望对php教程有兴趣的朋友有所帮助。
其它类似信息

推荐信息