Php advertisement calling code (supporting Flash call)

Source: Internet
Author: User
Php advertisement calling code (supporting Flash call), which is very convenient for loading advertisements on php pages. For more information, see.

Php advertisement calling code (supporting Flash call), which is very convenient for loading advertisements on php pages. For more information, see.

The call method is as follows: The DebugStr function is similar to an echo function.
The Code is as follows:
DebugStr ('$ Adv-> getContentById ($ id); $ id is the advertisement number. Only one call is called and the returned content is a string ');
Echo Adv: getContentById (35 );
DebugStr ('$ Adv-> getContentByIdJS ($ id); $ id is the advertisement number, only one is called, and the returned content is the JS string ');
Echo Adv: getContentByIdJS (35 );
DebugStr ('$ Adv-> getContentByOrder ($ id); $ id is the advertisement number. Only one ID is called in reverse order and the returned content is a string ');
Echo Adv: getContentByOrder (4 );
DebugStr ('$ Adv-> getContentByOrderJS ($ id); $ id is the advertisement number. Only one reverse ID is called and the returned content is a JS string ');
Echo Adv: getContentByOrderJS (4 );
Echo '';

Class:
The Code is as follows:
/**
* Description: it is an advertisement class that facilitates the call of the AD list and content.
* Required: Database Class
* Supported: Only PHP5 and single-piece mode are supported.
*
* @ Author Zerolone
* @ Version 2011-1-6 11:32:06
* Call Method
* Adv: getContentById ($ id); $ id indicates the ad id. Only one request is called and the returned content is a string.
* Adv: getContentByIdJs ($ id); $ id is the advertisement number, only one is called, and the returned content is a JS string.
* Adv: getContentByOrder ($ order); $ order indicates the corresponding value. Only one ID is called in reverse order and the returned content is a string.
* Adv: getContentByOrderJs ($ order); $ order corresponds to the order. Only one ID is called in reverse order and the returned content is a JS string.
*/
Class Adv {
Static $ Id = 0; // No.
Static $ Order = 0; // Order
Static $ JS = 0; // whether to use JS. 0 indicates no.
/**
* According to the Id, only one advertisement is returned.
*
* @ Param No. $ id
*
*/
Public static function getContentById ($ id ){
Self: $ Id = $ id;
Return self: getContent ();
}
/**
* Return the ad content Js Based on the Id and only call one
*
* @ Param No. $ id
*
*/
Public static function getContentByIdJS ($ id ){
Self: $ Id = $ id;
Self: $ JS = 1;
Return self: getContent ();
}
/**
* According to Order, only one advertisement content is returned.
*
* @ Param No. $ Order
*
*/
Public static function getContentByOrder ($ order ){
Self: $ Order = $ order;
Return self: getContent ();
}
/**
* According to Order, return the ad content Js and only call one
*
* @ Param No. $ Order
*
*/
Public static function getContentByOrderJS ($ order ){
Self: $ Order = $ order;
Self: $ JS = 1;
Return self: getContent ();
}
/**
* Generate an advertisement and only call one
*
* @ Return ad content
*/
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];
}
// Determine the type
$ FileName_Ext = strtoupper (pathinfo ($ FileName, PATHINFO_EXTENSION ));
If ($ FileName_Ext = 'swf '){
// Flash Advertisement
$ ReturnContent ='



';$ ReturnContent. =' ';$ ReturnContent. =' ';$ ReturnContent. =' ';$ ReturnContent. ='
';
$ ReturnContent. ='



';$ ReturnContent. =' ';$ ReturnContent. =' ';$ ReturnContent. =' ';$ ReturnContent. ='
';
$ ReturnContent. ='

';
$ ReturnContent. ='

';
$ ReturnContent. ='





';$ ReturnContent. =' ';$ ReturnContent. =' ';$ ReturnContent. =' ';$ ReturnContent. ='
';
$ ReturnContent. ='

';
$ ReturnContent. ='

';
$ ReturnContent. ='';
$ ReturnContent. ='';
$ ReturnContent. ='';
$ ReturnContent. ='';
$ ReturnContent. ='';
$ ReturnContent. ='
';
$ ReturnContent. ='
';
} Else {
// Image Advertisement
$ ReturnContent = '';
}
// If the JS method is called
If (self: $ JS ){
$ ReturnContent = 'document. write ("'. addslashes ($ ReturnContent ).'");';
}
// Reset the default value. Here the single-piece mode is used.
Self: $ Id = 0;
Self: $ Order = 0;
Self: $ JS = 0;
Return $ ReturnContent;
}
}
?>

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.