当前位置: 首页 > 图文教程 > 网络编程 > PHP > PHP个人网站架设连环讲(三)

PHP
第十三节--对象串行化 -- Classes and Objects in PHP5 [13]
第十一节--重载 -- Classes and Objects in PHP5 [11]
第十节--抽象方法和抽象类 -- Classes and Objects in PHP5 [10]
第九节--绑定 -- Classes and Objects in PHP5 [9]
第八节--访问方式 -- Classes and Objects in PHP5 [8]
第七节--类的静态成员 -- Classes and Objects in PHP5 [7]
第六节--访问属性和方法 -- Classes and Objects in PHP5 [6]
第五节--克隆 -- Classes and Objects in PHP5 [5]
第四节--构造函数和析构函数 -- Classes and Objects in PHP5 [4
第三节--定义一个类 -- Classes and Objects in PHP5 [3]
第二节--PHP5 的对象模型 -- Classes and Objects in PHP5 [2]
第一节--面向对象编程 -- Classes and Objects in PHP5 [1]
初探 PHP5 (二)
初探 PHP5 (一)
SSI使用详解(二)
SSI使用详解(一)
Cookie及其使用(二)
Cookie及其使用(一)
实现跨域名Cookie
两种统计当前在线人数的方法

PHP个人网站架设连环讲(三)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 108 ::
收藏到网摘: n/a

三 首页新闻发布,让你更新更轻松(中)

上次我们做了一个文件头(至于文件尾,请大家自己做,假设为tail.php),一个函数的模块,现在,我们来一个基本功能的实现,也就是动态发布啦

以下为引用的内容:

<?php
include("makestr.php";
include("head.php");
$newspath="/announce/"; //以文本文件存放的新闻文件的目录
$newsfile=array();//准备新闻数组
$hd=dir($newspath); //目录句柄
while($filename=$hd->read()){ //获取全部文件
$s=strtolower($filename);
if(strstr($s,".txt")){
//检测最新的修改日期
$lastchanged=fileatime($newspath.$filename);
$newsfile[$filename]=$lastchanged;
}
}
arsort($newsfile); //文件按时间排序
//输出文件
for(reset($newsfile);$key=key($newsfile);next($newsfile))
{$fa=file($newspath.$key);
$n=count($fa);
echo "<p>".date("d.m.Y-H:i:s".$newsfile[$key])."<br>\n";
for($i=0;$i<$n;$i=$i+1){
$s=chop($fa[$i]);//去除空格
$s=htmlspecialchars($s);
print $s."</p>\n";

}
}
$hd->close(); //释放句柄
include("tail.php"); 
?>

这样,将你的新闻文本传上你根目录的annouce子目录下,就可以方便发布新闻了。但真正的方便还不在于这,比如说,当新闻过时的时候,程序能自动删除它,多好。不用ftp,直接在线写下要新发的公告,多方便。好了,且听下回分解。