文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>在*.htm或*.html文件中放计数器和日历

在*.htm或*.html文件中放计数器和日历

时间:2007-02-17  来源:PHP爱好者

一般,自己做的文本计数器或者日历要放在*.PHP文件中,如果一定要用htm或html做文件扩展名(例如index.html),还能放计数器或者日历吗?回答是肯定的。方法是先用PHP的图形输出功能画出所要的图形,再利用HTTP标头信息使html文件能把这个PHP文件当作一个图形文件来处理,在*.htm或*.html文件中放计数器或日历变得和放置一个图片文件一样简单!下面是计数器图形文件count.php和日历文件date.php的PHP源代码:
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
---------------文件count.php(计数器)----------
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
<?
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
if(!file_exists("count.txt"))
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
exec("echo 0 > count.txt");
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$fp = fopen("count.txt", "r+");
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$FileSize = filesize("count.txt");
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$Count = fgets($fp, $FileSize + 1);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$Count += 1;
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
fseek($fp, 0);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
fputs($fp, $Count);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
fclose($fp);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$strCount = strval($Count); //获得的记数转成字符串
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$strCount = Chop($strCount);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$CountLen = strlen($strCount);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
for($i = 0; $i <8 - $CountLen; $i ++) //计数器定为8位,不足则补零
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$strCount = "0".$strCount;
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
//创建图象
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$img = imagecreate(90, 26);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
//匹配颜色
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$black = imagecolorallocate($img, 0, 0, 0);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$green = imagecolorallocate($img, 0, 255, 0);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$fgray = imagecolorallocate($img, 180, 180, 180);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$dgray = imagecolorallocate($img, 130, 130, 130);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$gray = imagecolorallocate($img, 160, 160, 160);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
//绘制边框
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
imagerectangle($img, 0, 0, 89, 25, $fgray);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
imagerectangle($img, 1, 1, 88, 24, $dgray);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
imagerectangle($img, 2, 2, 87, 23, $gray);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
//输出记数
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
imagestring($img, 4, 13, 5, $strCount, $green);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
//输出图片
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
header("Content-type:image/png");
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
imageinterlace($img, 1);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
imagepng($img);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
?>
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
---------------文件date.php(日历)----------------------------
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
<?
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
//创建图象
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$img = imagecreate(132, 26);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
//匹配颜色
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$black = imagecolorallocate($img, 0, 0, 0);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$green = imagecolorallocate($img, 0, 255, 0);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$fgray = imagecolorallocate($img, 180, 180, 180);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$dgray = imagecolorallocate($img, 130, 130, 130);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
$gray = imagecolorallocate($img, 160, 160, 160);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
//绘制边框
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
imagerectangle($img, 0, 0, 131, 25, $fgray);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
imagerectangle($img, 1, 1, 130, 24, $dgray);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
imagerectangle($img, 2, 2, 129, 23, $gray);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
//输出日期
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
imagestring($img, 4, 11, 5, date("Y.m.d.D"), $green);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
//输出图片
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
header("Content-type:image/png");
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
imageinterlace($img, 1);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
imagepng($img);
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
?>
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x

chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
只要把这两个文件当作图形文件插入到HTML文件的任何地方,就成为计数器和日历了,可以到下列地址看看效果:
chin a i t p oe er . co myvTEW8IR8se9zhQFjYlqNcp1x
http://youziyun.oso.com.cn
php爱好者站 http://www.phpfans.net 文章|教程|下载|源码|论坛.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载