新闻文件以文本文件.txt的格式存放在一个固定的目录下,新闻的发布可以自动完成,该过程由两部分组成: 第一是新闻的显示,由shownews.php脚本实现,代码如下:
<table border="0" width="90%"> <?php //在新闻文件中的第一行放新闻的标题 //新闻文件必须是文本文件(.txt) $newspath = "./news/"; // 修改新闻文件存放的目录 $newsfile = array(); $hd = dir($newspath); while ($filename = $hd->read()) { $s = strtolower($filename); if (strstr($s, ".txt")) { $lastchanged = filemtime($newspath . $filename); $newsfile[$filename] = $lastchanged; } } arsort($newsfile); for (reset($newsfile); $key = key($newsfile); next($newsfile)) { print "<tr><td>n"; $fa = file($newspath . $key); $s = trim($fa[0]); $s = htmlspecialchars($s); $lk = strlen($key); $a = substr($key, 0, $lk - 4); $s = "<a href=" . /pubnews . php ? id = ".$a."" target=_blank>" . $s . "</a>"; print $s . " n"; print "(" . date("Y年m月d日 - H:i:s", $newsfile[$key]) . ") n"; print "</td></tr>"; } $hd->close(); ?> </table> 在显示新闻的地方放入代码: <?php require "./shownews.php"; 第二部分为新闻的发布,由pupnews . php脚本实现,代码如下: < ? phpif ($id == "") { Header("Location: ./shownews.php"); } ?> <html> <head> <meta content="chenqiang" name=Author> <?php $filename = "./news/" . $id . ".txt"; $fa = file($filename); $n = count($fa); $s = trim($fa[0]); $s = htmlspecialchars($s); $t = " - news by waterwall"; print "<title>" . $s . $t . "</title>n"; ?> </head> <body> <?php //输出文本标题 print "<blockquote>n"; print "<b><center>" . $s . "n"; print "</center></b> <p>n"; //输出文本正文 for ($i = 1; $i < $n; $i+= 1) { $s = chop($fa[$i]); $s = htmlspecialchars($s); $s = trim($s); print " " . $s . " n"; } print "</p></blockquote>n"; ?> </body> </html>
用数据库也可实现,这只是文件形式的实现方式。
文章网址:
随意转载^^但请附上教程地址。
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章
刺客信条阴影:贝壳谜语解决方案
3 周前ByDDD
Windows 11 KB5054979中的新功能以及如何解决更新问题
2 周前ByDDD
在哪里可以找到原子中的起重机控制钥匙卡
3 周前ByDDD
<🎜>:死铁路 - 如何完成所有挑战
4 周前ByDDD
Atomfall指南:项目位置,任务指南和技巧
1 个月前ByDDD

热工具

Dreamweaver CS6
视觉化网页开发工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

SublimeText3汉化版
中文版,非常好用