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.
Copy codeThe 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:
Copy codeThe 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;
}
}
?>