Home > php教程 > php手册 > PHP个人网站架设连环讲(三)_php基础

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

WBOY
Release: 2016-05-17 09:07:08
Original
1625 people have browsed it

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

上次我们做了一个文件头(至于文件尾,请大家自己做,假设为tail.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 "

".date("d.m.Y-H:i:s".$newsfile[$key])."
\n";
for($i=0;$i$s=chop($fa[$i]);//去除空格
$s=htmlspecialchars($s);
print $s."

\n";

}
}
$hd->close(); //释放句柄
include("tail.php");  
?>
这样,将你的新闻文本传上你根目录的annouce子目录下,就可以方便发布新闻了。但真正的方便还不在于这,比如说,当新闻过时的时候,程序能自动删除它,多好。不用ftp,直接在线写下要新发的公告,多方便。好了,且听下回分解。  
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template