在資料庫中建立欄位,記錄檔案名稱,每產生一個檔案,將自動產生的檔案名稱存入資料庫,對於推薦文章,只需指向存放靜態檔案的指定檔案夾中的該頁面即可。 利用PHP操作文章列表,存為字串,產生頁面時替換此字串即可。如,在頁面中放置文章列表的表格加入標記{articletable},而在 PHP處理檔案中:
PHP操作文章列表實現代碼:
- < ?php
- $title = "http://siyizhu.com測試模板";
- $file = "TwoMax Inter test templet,
author:Matrix@Two_Max";
- $fp = fopen ("temp.html","r");
- $content = fread ($fp,filesize ("temp.html"));
- $content = str_replace ("{file}",$file,$content);
- $content = str_replace ("{title}",$title,$content);
- // 產生列表開始
- $list = '';
- $sql = "select id,title,filename from article";
- $query = mysql_query ($sql);
- while ($result = mysql_fetch_array ($query)){
- $list .= '.$root.$result['filename'].'
target=_blank>'.$result['title'].'a><br>';
- }
- $content .= str_replace ("{articletable}"
,$list,$content);
- //產生列表結束
- // echo $content;
- $filename = "test/test.html";
- $handle = fopen ($filename,"w");
//開啟檔案指標,建立檔案
- /*
- 檢查檔案是否被建立且可寫
- */
- if (!is_writable ($filename)){
- die ("檔案:".$filename."不可寫,
請檢查其屬性後重試!");
- }
- if (!fwrite ($handle,$content)){
//將資訊寫入檔案
- die ("組建檔案".$filename."失敗!");
- }
- fclose ($handle); //關閉指標
- die ("建立檔案".$filename."成功!");
- ?>
以上這段程式碼範例就是PHP操作文章列表的相關使用方法。
http://www.bkjia.com/PHPjc/445955.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445955.htmlTechArticle在資料庫中建立欄位,記錄檔案名稱,每產生一個檔案,將自動產生的檔案名稱存入資料庫,對於推薦文章,只需指向存放靜態檔案的指定檔案...