php自动生成新闻页,自动发布新闻页面的php代码
自動發布新聞頁面的php代碼
新聞文件以文本文件.txt的格式存放在一個固定的目錄下,新聞的發布可以自動完成。
該過程由兩部分組成:
第一是新聞的顯示,由shownews.php腳本實現,代碼如下:
〈tableborder="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="〈ahref="./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腳本實現,代碼如下:
〈?php
if($id=="")
{
Header("Location:./shownews.php");
}
?〉
〈html〉
〈head〉
〈metacontent="chenqiang"name=Author〉
〈?php
$filename="./news/".$id.".txt";
$fa=file($filename);
$n=count($fa);
$s=trim($fa[0]);
$s=htmlspecialchars($s);
$t="-newsbywaterwall";
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〉
用數據庫也可實現,這只是文件形式的實現方式。
分享到:
總結
以上是生活随笔為你收集整理的php自动生成新闻页,自动发布新闻页面的php代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 系统监控 php,Linux
- 下一篇: php程序网站整站301,织梦dede怎