熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> PHP編程 >> 正文

PHP個人網站架設連環講(三)

2022-06-13   來源: PHP編程 

  三 首頁新聞發布讓你更新更輕松(中)

  上次我們做了一個文件頭(至於文件尾請大家自己做假設為tailphp)一個函數的模塊現在我們來一個基本功能的實現也就是動態發布啦

  <?php
  include(makestrphp;
  include(headphp);
  $newspath=/announce/; //以文本文件存放的新聞文件的目錄
  $newsfile=array();//准備新聞數組
  $hd=dir($newspath); //目錄句柄
  while($filename=$hd>read())
  {
   //獲取全部文件
   $s=strtolower($filename);
   if(strstr($stxt))
   {
    //檢測最新的修改日期
    $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(dmYH:i:s$newsfile[$key])<br>\n;
   for($i=;$i<$n;$i=$i+)
   {
    $s=chop($fa[$i]);//去除空格
    $s=htmlspecialchars($s);
    print $s</p>\n;
   }
  }
  $hd>close(); //釋放句柄
  include(tailphp); 
  ?>

  這樣將你的新聞文本傳上你根目錄的annouce子目錄下就可以方便發布新聞了但真正的方便還不在於這比如說當新聞過時的時候程序能自動刪除它多好不用ftp直接在線寫下要新發的公告多方便好了且聽下回分解 


From:http://tw.wingwit.com/Article/program/PHP/201311/21499.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.