PHP随机生成广告图片的实例 代码
2013-12-13 08:06
771 查看
PHP随机生成广告图片:
<?php /*
+------------------------------------------------------------------+
| MikeCherim.com |
| PHP: Ad Generator |
| PHP Hypertext Preprocessor |
| Copyright Dec 2006 |
| Use with attribution by visible link please! |
| Attribute to: <a href="http://green-beast.com/">Mike Cherim</a> |
+------------------------------------------------------------------+
*/ ?>
<?php
/*
* GENERAL INFORMATION:
* Implementation is simple and straight forward. I offer the script
* in two sections. The array of arrays, and the output. Both can be
* combined and placed on the page right where they're needed, or put
* into two sections on the page, or the arrays can be placed in a
* separate file and included. It's up to you and will probably be
* decided by the number of ad arrays you will include.
*/
?>
<?php
/*
* PART 1 - THE ARRAY OF ARRAYS
* I have expanded this to make the script easier to negotiate
* If you're using constant values, you can remove those parts.
* If wanted, you could also add captions to the arrays below.
*/ www.jbxue.com
$ad_rand = array(
1 => array(
'url' => 'somesite1.com', // Url of advertiser or stats recording redirect
'img' => 'image1.jpg', // Add file name, type, even path if needed
'ttl' => 'Tool Tip 1', // Recommended title text (tool tip)
'alt' => 'Alt Text 1' // Required alternate text
),
2 => array(
'url' => 'somesite2.com',
'img' => 'image2.jpg',
'ttl' => 'Tool Tip 2',
'alt' => 'Alt Text 2'
),
3 => array(
'url' => 'somesite3.com',
'img' => 'image3.jpg',
'ttl' => 'Tool Tip 3',
'alt' => 'Alt Text 3'
),
4 => array(
'url' => 'somesite4.com',
'img' => 'image4.jpg',
'ttl' => 'Tool Tip 4',
'alt' => 'Alt Text 4'
),
5 => array(
'url' => 'somesite5.com',
'img' => 'image5.jpg',
'ttl' => 'Tool Tip 5',
'alt' => 'Alt Text 5'
),
);
?>
<?php
/*
* PART 2 - THE OUTPUT
* This is simple, simply place the link/image line where needed.
* I included the path as a fixed part in this example
* I added an optional container div. Image string is XHTML.
* Note that the ?> of the last part and <?php of this part
* can be removed if you decide to combine the two sections.
* Also note that contstant variables like path (shown) and
* height and width dimensions can be added below and removed
* from the section above if that better meets your needs
*/
$ad = array_rand($ad_rand);
echo('
<div>
<a href="http://'.$ad_rand[$ad]['url'].'/" title="'.$ad_rand[$ad]['ttl'].'">
<img src="http://images.cnblogs.com/'.$ad_rand[$ad]['img'].'" width="468" height="60" alt="'.$ad_rand[$ad]['alt'].'" />
</a>
</div>
');
?>
<?php /*
+------------------------------------------------------------------+
| MikeCherim.com |
| PHP: Ad Generator |
| PHP Hypertext Preprocessor |
| Copyright Dec 2006 |
| Use with attribution by visible link please! |
| Attribute to: <a href="http://green-beast.com/">Mike Cherim</a> |
+------------------------------------------------------------------+
*/ ?>
<?php
/*
* GENERAL INFORMATION:
* Implementation is simple and straight forward. I offer the script
* in two sections. The array of arrays, and the output. Both can be
* combined and placed on the page right where they're needed, or put
* into two sections on the page, or the arrays can be placed in a
* separate file and included. It's up to you and will probably be
* decided by the number of ad arrays you will include.
*/
?>
<?php
/*
* PART 1 - THE ARRAY OF ARRAYS
* I have expanded this to make the script easier to negotiate
* If you're using constant values, you can remove those parts.
* If wanted, you could also add captions to the arrays below.
*/ www.jbxue.com
$ad_rand = array(
1 => array(
'url' => 'somesite1.com', // Url of advertiser or stats recording redirect
'img' => 'image1.jpg', // Add file name, type, even path if needed
'ttl' => 'Tool Tip 1', // Recommended title text (tool tip)
'alt' => 'Alt Text 1' // Required alternate text
),
2 => array(
'url' => 'somesite2.com',
'img' => 'image2.jpg',
'ttl' => 'Tool Tip 2',
'alt' => 'Alt Text 2'
),
3 => array(
'url' => 'somesite3.com',
'img' => 'image3.jpg',
'ttl' => 'Tool Tip 3',
'alt' => 'Alt Text 3'
),
4 => array(
'url' => 'somesite4.com',
'img' => 'image4.jpg',
'ttl' => 'Tool Tip 4',
'alt' => 'Alt Text 4'
),
5 => array(
'url' => 'somesite5.com',
'img' => 'image5.jpg',
'ttl' => 'Tool Tip 5',
'alt' => 'Alt Text 5'
),
);
?>
<?php
/*
* PART 2 - THE OUTPUT
* This is simple, simply place the link/image line where needed.
* I included the path as a fixed part in this example
* I added an optional container div. Image string is XHTML.
* Note that the ?> of the last part and <?php of this part
* can be removed if you decide to combine the two sections.
* Also note that contstant variables like path (shown) and
* height and width dimensions can be added below and removed
* from the section above if that better meets your needs
*/
$ad = array_rand($ad_rand);
echo('
<div>
<a href="http://'.$ad_rand[$ad]['url'].'/" title="'.$ad_rand[$ad]['ttl'].'">
<img src="http://images.cnblogs.com/'.$ad_rand[$ad]['img'].'" width="468" height="60" alt="'.$ad_rand[$ad]['alt'].'" />
</a>
</div>
');
?>
相关文章推荐
- PHP随机生成广告图片的实例分享
- 随机字符串生成图片 PHP代码
- 随机漂浮图片广告实例代码
- [PHP实例] php生成圆角图片代码
- java随机动态生成汉字验证码图片的实例代码分享
- java随机动态生成汉字验证码图片的实例代码分享
- php 生成随机验证码图片代码
- php+ajax无刷新上传图片实例代码
- 用PHP程序实现随机广告图片显示
- PHP实现随机生成水印图片功能
- PHP生成一张含有二维码的图片(文章末尾附代码下载链接)
- 【代码实现】PHP生成各种随机验证码
- php图片裁剪实例代码
- 生成随机字符串和验证码的类的PHP实例
- PHP生成图片随机验证码的方法
- 刷新一次变一次的图片代码-PHP随机显示图片代码:可制作头像或签名
- javascript 随机广告代码(图片广告)
- 利用iOS绘制图片生成随机验证码示例代码
- 生成随机验证图片--ASP.NET中常用代码之二