上次我们做了一个文件头(至于文件尾,请大家自己做,假设为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."
}
}
$hd->close(); //释放句柄
include("tail.php");
?>
这样,将你的新闻文本传上你根目录的annouce子目录下,就可以方便发布新闻了。但真正的方便还不在于这,比如说,当新闻过时的时候,程序能自动删除它,多好。不用ftp,直接在线写下要新发的公告,多方便。好了,且听下回分解。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools