> 백엔드 개발 > PHP 튜토리얼 > 利用PHP实现与ASPBanner组件相似的类_PHP

利用PHP实现与ASPBanner组件相似的类_PHP

WBOY
풀어 주다: 2016-06-01 12:42:29
원래의
845명이 탐색했습니다.

/*******************************************************
作者: 吴振亨 (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=" Redirect;
        $LinkString.="?url=".$AdData[$id]["url"];
        $LinkString.="" Target="".$this->Target;
        $LinkString.="" Title="".$AdData[$id]["title"];
        $LinkString.="" >";
        $LinkString.=" 利用PHP实现与ASPBanner组件相似的类_PHPBorder;
        $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");
*/
?>  

【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】    

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿