php生成靜態html分頁實現方法

2022-02-22 20:23:42 字數 1349 閱讀 4158

<?php

$conn=mysql_connect('localhost','root','wy')

or die('連線失敗:'.mysql_error());

//選擇資料表

if (mysql_select_db('mynews',$conn))

else

@header("content-type: text/html; charset=utf-8");

mysql_query("set names 'utf8'");

$fp = fopen ("temp.html","r");

$content = fread ($fp,filesize ("temp.html"));

$onepage =2;

$sql = "select id from news";

$query = mysql_query ($sql);

$num = mysql_num_rows ($query);

$allpages = ceil ($num / $onepage);

for ($i = 0;$i<$allpages; $i++) else

$start = $i * $onepage;

$list = '';

$sql_for_page = "select * from news limit $start,$onepage";

$result=mysql_query($sql_for_page);

while($row=mysql_fetch_array($result))

$content1 = str_replace ("",$list.$i,$content);

//分頁

$list1 = '';

for ($j = 0;$j<$allpages; $j++) else

}$content2 = str_replace ("",$list1,$content1);

if (is_file ($indexpath))

$handle = fopen ($indexpath,"w"); //開啟檔案指標,建立檔案

/*檢查檔案是否被建立且可寫

*/if (!is_writable ($indexpath))

if (!fwrite ($handle,$content2))

fclose ($handle); //關閉指標

}fclose ($fp);

die ("生成分頁檔案完成,如生成不完全,請檢查檔案許可權系統後重新生成!");

?>

temp.html

this is a file's templets

分頁        

PHP生成靜態html

一 建立muban.html檔案,新增如下 內容 二 建立php檔案,新增如下 header content type text html charset utf 8 將資料存入二維陣列 con array array 文章標題1 文章內容1 array 文章標題2 文章內容2 array 文章標題...

php生成靜態html頁面

ob start 是開啟緩衝區的,就是要把您需要生成的靜態檔案的內容快取在這裡 ob get contents 是讀出緩衝區裡的內容,下面有 為例 ob end clean 這個比較重要,只有使用了這個函式後,緩衝區裡的內容才會讀 ob start require index.php 模板頁面 te...

PHP 批量生成靜態html

本示例圍繞 cms 系統的靜態頁面方案出發,展示批量生成靜態 html 功能。注 本文程式只能在 windows 的 dos 或 linux 下執行 php 命令來執行。本示例主要有4個檔案 config.inc.php 配置檔案 db.class.php 資料庫 pdo 類 model.class...