欧美成人片一区二区三区,久久碰人妻一区二区三区,久久婷婷激情综合色综合俺也去,狂野欧美性猛交免费视频,久久夜色精品国产亚洲

27
2017/08

html模板生成靜態(tài)頁面及模板分頁處理

發(fā)布時(shí)間:2017-08-27 17:45:47
發(fā)布者:pengyifeng
瀏覽量:
0

它只讓你修改頁面的某一部分,當(dāng)然這“某一部分”是由你來確定的。美工先做好一個(gè)頁面,然后我們把這個(gè)頁面當(dāng)作模板(要注意的是這個(gè)模板就沒必要使用EditRegion3這樣的代碼了,這種代碼是Dreamwerver為了方便自己設(shè)計(jì)而弄的標(biāo)識(shí)),把這個(gè)模板中我們需要改變的地方用一個(gè)與HTML可以區(qū)分的字符代替,如“{title}”、“[title]”。在生成靜態(tài)頁面的時(shí)候只需要把數(shù)據(jù)和這些字符串替換即可。這就是模板的含義了。

新建一個(gè)php頁面和一個(gè)html頁面[模板頁];注:如果是從數(shù)據(jù)庫調(diào)用數(shù)據(jù),則將數(shù)據(jù)以數(shù)組的形式保存,然后循環(huán)生成;
在php頁面,打開html頁面->讀取html頁面的內(nèi)容->替換參數(shù)->新建(打開)一個(gè)新的html頁面->將替換的內(nèi)容寫入新文件中->關(guān)閉新文件->生成成功;

$open = fopen("template.htm","r"); //打開模板文件
$content = fread($open,filesize("template.htm")); //讀取模板文件內(nèi)容//
print_r($content);$content = str_replace("{title}","測試標(biāo)題",$content);//替換
$content = str_replace("{contents}","測試內(nèi)容",$content);
$newtemp = fopen("1.htm","w");//生成,用寫入方式打開一個(gè)不存在(新)的頁面
fwrite($newtemp,$content);//將剛剛替換的內(nèi)容寫入新文件中
fclose($newtemp);echo "生成";

如我們指定分頁時(shí),每頁20篇。某子頻道列表內(nèi)文章經(jīng)數(shù)據(jù)庫查詢?yōu)?5條,則,首先我們通過查詢得到如下參數(shù):1,總頁數(shù);2,每頁篇數(shù)。i++)die(""." role="presentation" style="margin: 0px; padding: 0px; display: inline; line-height: normal; word-wrap: normal; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255); position: relative;">,,環(huán)執(zhí)。die("創(chuàng)".filename."成功!";這句去掉,放到循環(huán)后的顯示,因?yàn)樵撜Z句將中止程序執(zhí)行。例:

$fp= fopen ("temp.html","r");
$content= fread ($fp,filesize ("temp.html"));
$onepage= ’20’;
$sql    = "select id from article where channel=’$channelid’";
$query  = mysql_query ($sql);
$num    = mysql_num_rows ($query);
$allpages= ceil ($num / $onepage);
for ($i = 0;$i<$allpages; $i++){
    if ($i == 0){
        $indexpath = "index.html";
    } else {
        $indexpath = "index_".$i."html";
    }
    $start = $i * $onepage;
    $list  = ’’;
    $sql_for_page = "select name,filename,title from article where channel=’$channelid’ limit $start,$onepage";
    $query_for_page = mysql_query ($sql_for_page);
    while ($result = $query_for_page){
        $list .= ’’.$title.’
’;     }     $content = str_replace ("{articletable}",$list,$content);     if(is_file ($indexpath)){         @unlink ($indexpath); //若文件已存在,則刪除     }     $handle = fopen ($indexpath,"w"); //打開文件指針,創(chuàng)建文件     if (!is_writable ($indexpath)){         echo "文件:".$indexpath."不可寫,請檢查其屬性后重試!"; //修改為echo     }     if (!fwrite ($handle,$content)){   //將信息寫入文件         echo "生成文件".$indexpath."失??!"; //修改為echo     }     fclose ($handle); //關(guān)閉指針 } fclose ($fp); die ("生成分頁文件完成,如生成不完全,請檢查文件權(quán)限系統(tǒng)后重新生成!");
返回列表