|
|
演示
http://phpscriptexpert.com/demo/simple_ad_rotator/example.php
刷新会看到不同的广告 按F5就可以刷新
To define a new ad just insert a new line like this:
$ad[] = array("Ad title ", "Ad description ", "Display URL", "URL");
To display the ads include the file "ad_rotator.php" and after that call the functions show_ads().
Example:
<?php
include ("/path/to/ad_rotator.php");
show_ads(3); // this will display 3 ads
show_ads(1); // this will display 1 ad
?>
<?php
/*************************************************
* Simple AD Rotator
*
* Version: 1.0
* Date: 2007-08-30
*
* Include this php file into your site and call the
* show_ads() function with a number of ads
* you want to display.
*
* See example.php
*
****************************************************/
//USAGE $ad[] = array("Title", "Description", "display url", "url");
$ad[] = array("Title 0", "Some description for Ad 0", "www.google.com", "http://www.google.com");
$ad[] = array("Title 1", "Some description for Ad 1", "www.google.com", "http://www.google.com");
$ad[] = array("Title 2", "Some description for Ad 2", "www.google.com", "http://www.google.com");
$ad[] = array("Title 3", "Some description for Ad 3", "www.google.com", "http://www.google.com");
$ad[] = array("Title 4", "Some description for Ad 4", "www.google.com", "http://www.google.com");
$ad[] = array("Title 5", "Some description for Ad 5", "www.google.com", "http://www.google.com");
$ad[] = array("Title 6", "Some description for Ad 6", "www.google.com", "http://www.google.com");
$ad[] = array("Title 7", "Some description for Ad 7", "www.google.com", "http://www.google.com");
$ad[] = array("Title 8", "Some description for Ad 8", "www.google.com", "http://www.google.com");
$ad[] = array("Title 9", "Some description for Ad 9", "www.google.com", "http://www.google.com");
// Function to display random ads from the list
function show_ads($number_of_ads=1){
// Loading the ads list
global $ad;
// maximul number of ads = number of ads
if($number_of_ads > count($ad)){
$number_of_ads = count($ad);
}
// Initialize the random generator
list($usec, $sec) = explode(' ', microtime());
srand((float) $sec + ((float) $usec * 100000));
// select random ads
$rand_keys = array_rand($ad, $number_of_ads);
// creade ads
$show_ads = "<table><tr>";
for($i=0; $i<$number_of_ads; $i++){
$e = $ad[$rand_keys[$i]];
$show_ads .= "
<td onClick=\"document.location='{$e[3]}'\" title='{$e[0]}' width='180' style='cursor:pointer'>
<a href='{$e[3]}' style='font:13px Arial; font-weight:bold; color: #0000ff'>{$e[0]}</a><br>
<span style='font:12px Arial; color: #333333'>{$e[1]}</span><br>
<a href='{$e[3]}' style='font:10px Arial; color: #009900'><i>{$e[2]}</i></a>
</td>
";
}
$show_ads .= "</tr></table>";
echo $show_ads;
}
?> |
|