当你在网上安放好自己的网页时,你是不是感到因为要经常更新你的网页的背景而厌烦,
下面我来介绍两个自动更新背景的简单办法:
一:每日自动更新
首先准备好7幅背景图片,并以以下文件名命名:
monday.gif, tuesday.gif, wednesday.gif, thursday.gif, friday.gif, saturday.gif, and sunday.gif
<?php
/////////////////
// file:bg.inc //
/////////////////
$path_to_images = "images/"; //背景图片文件存放路径
$file_extension = ".gif"; //背景图片文件的扩展名
$current_date = getdate();
$this_weekday = $current_date["weekday"];
$this_weekday = strtolower($this_weekday);
$this_weekday = $path_to_images.$this_weekday;
$this_weekday = $this_weekday.$file_extension;
?>
然后在要自动更新背景的页面中加入
<? require("bg.inc"); ?>
<body background="<?php echo $this_weekday; ?>">
二:每次打开页面随机更新背景
首先准备10幅背景图片,并以以下文件名命名:
0.gif, 1.gif, 2.gif, 3.gif, 4.gif, 5.gif, 6.gif, 7.gif, 8.gif, 9.gif
<?php
/////////////////
// file:bg.inc //
/////////////////
$path_to_images = "images/"; //背景图片文件存放路径
$file_extension = ".gif"; //背景图片文件的扩展名
srand((double)microtime()*1000000);
$filename = rand();
$filename = $path_to_images.$filename;
$filename = $filename.$file_extension;
?>
然后在要自动更新背景的页面中加入
<? require("bg.inc"); ?>
<body background="<?php echo $filename; ?>">
|