php 广告调用类代码(支持Flash调用)
php 广告调用类代码(支持Flash调用),非常方便php页面中加载广告。需要的朋友可以参考下。
调用方式如下:其中DebugStr这个函数就是类似一个echo。
代码如下:
DebugStr('$Adv->getContentById($id); $id为广告编号, 仅调用一条,返回内容为字符串');
echo Adv::getContentById(35);
DebugStr('$Adv->getContentByIdJS($id); $id为广告编号, 仅调用一条,返回内容为JS字符串');
echo Adv::getContentByIdJS(35);
DebugStr('$Adv->getContentByOrder($id); $id为广告编号, 仅调用ID倒序一条,返回内容为字符串');
echo Adv::getContentByOrder(4);
DebugStr('$Adv->getContentByOrderJS($id); $id为广告编号, 仅调用ID倒序一条,返回内容为JS字符串');
echo Adv::getContentByOrderJS(4);
echo '
';
类如下:
代码如下:
/**
* 说明:广告类,方便广告列表、内容的调用。
* 需要:数据库类
* 支持:仅支持PHP5,单件模式
*
* @author Zerolone
* @version 2011-1-6 11:32:06
* 调用方法
* Adv::getContentById($id); $id为广告编号, 仅调用一条,返回内容为字符串
* Adv::getContentByIdJs($id); $id为广告编号, 仅调用一条,返回内容为JS字符串
* Adv::getContentByOrder($order); $order为对应, 仅调用ID倒序一条,返回内容为字符串
* Adv::getContentByOrderJs($order); $order对应顺序, 仅调用ID倒序一条,返回内容为JS字符串
*/
class Adv {
static $Id = 0; //编号
static $Order = 0; //顺序
static $JS = 0; //是否使用JS, 0为不使用
/**
* 根据Id, 返回广告内容,仅调用一条
*
* @param 编号 $id
*
*/
public static function getContentById($id){
self::$Id = $id;
return self::getContent();
}
/**
* 根据Id, 返回广告内容Js,仅调用一条
*
* @param 编号 $id
*
*/
public static function getContentByIdJS($id){
self::$Id = $id;
self::$JS = 1;
return self::getContent();
}
/**
* 根据Order, 返回广告内容,仅调用一条
*
* @param 编号 $Order
*
*/
public static function getContentByOrder($order){
self::$Order = $order;
return self::getContent();
}
/**
* 根据Order, 返回广告内容Js,仅调用一条
*
* @param 编号 $Order
*
*/
public static function getContentByOrderJS($order){
self::$Order = $order;
self::$JS = 1;
return self::getContent();
}
/**
* 生成一个广告内容,只调用一条
*
* @return 广告内容
*/
private function getContent(){
$ReturnContent='';
//------------------0-------1--------2--------3
$SqlStr = 'SELECT `pic`, `width`, `height`, `url` FROM '.TABLE_ADV;
if(self::$Id){
$SqlStr.= ' WHERE `id`=' . self::$Id;
}else{
$SqlStr.= ' WHERE `order`=' . self::$Order;
$SqlStr.= ' ORDER BY `id` DESC ';
}
$SqlStr.= ' LIMIT 1';
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$DB_Record = $MyDatabase->ResultArr [0];
$FileName = $DB_Record[0];
$Width = $DB_Record[1];
$Height = $DB_Record[2];
$Url = $DB_Record[3];
}
//判断类型
$FileName_Ext=strtoupper(pathinfo($FileName, PATHINFO_EXTENSION));
if ($FileName_Ext=='SWF'){
//Flash广告
$ReturnContent = '
'; $ReturnContent.= '
$ReturnContent.= ' | ';
}else{
//图片广告
$ReturnContent = '

}
//如果为调用JS方式
if(self::$JS){
$ReturnContent = 'document.write("'.addslashes($ReturnContent).'");';
}
//重置默认值,这里还是采用单件模式
self::$Id = 0;
self::$Order = 0;
self::$JS = 0;
return $ReturnContent;
}
}
?>
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사
KB5055523을 수정하는 방법 Windows 11에 설치되지 않습니까?
3 몇 주 전
By DDD
KB5055518을 수정하는 방법 Windows 10에 설치되지 않습니까?
3 몇 주 전
By DDD
<s> : 죽은 레일 - 늑대를 길들이는 방법
1 몇 달 전
By DDD
R.E.P.O.의 모든 적 및 괴물의 강도 수준
4 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
<garden> : 정원 재배 - 완전한 돌연변이 가이드
2 몇 주 전
By DDD

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)