【資料來源:http://www.wujianrong.com/archives/2006/10/php_html.html

總結有如下三種方法
1,下面使用模版的一個方法!
<?php
$fp = fopen ("templets.html","a");
if ($fp){
$fup = fread ($fp,filesize("templets.html"));
$fp2 = fopen ("html.shtml","w");
if ($fwrite ($fp2,$fup)){
$fclose ($fp);
$fcolse ($fp2);
die ("寫入模板成功");
} else {
fclose ($fp);
die ("寫入模板失敗!");
}
}
?>
簡單的將模板寫進一個文件中存為html.html


2,按時間生成html文件名

<?
$content = "這是一個以日期時間為文件名的靜態生成網頁的測試文件,文件名格式一般為<font color=#ff0000>年月日時分秒.html</font>";
$date = date('YmdHis');
$fp = fopen (date('YmdHis') . '.html',"w");//本函數可用來打開本地或者遠端的文件 'w' 開文件方式為寫入,文件指針指到開始處,並將原文件的長度設為 0。若文件不存在,則建立新文件。
if (fwrite ($fp,$content)){//格式是.int fwrite(int fp(文件名), string string(內容), int [length](長度));本函數將字符串 string 寫入文件資料流的指針 fp 上。若有指定長度 length,則會寫入指定長度字符串,或是寫到字符串結束。
fclose ($fp);//函數用來關閉已經打開的文件的指針 fp。成功返回 true,失敗則返回 false。
die ("寫入模板成功");
} else {
fclose ($fp);
die ("寫入模板失敗!");
}
echo ($content);
?>

3,下面為轉換文件名的一個方法
<?php
$s_fname = "93e.php";
$o_fname = "93e.htm";
ob_end_clean();
ob_start();
include($s_fname);
$length = ob_get_length();
$buffer = ob_get_contents();
$buffer = eregi_replace("r","",$buffer);
ob_end_clean();

$fp = fopen($o_fname,"w+");
fwrite($fp,$buffer);
fclose($fp);
?>

這樣就可以把
93e.php轉化為靜態的HTML文件了
要注意的是待轉換的文件裡不能有
ob_end_clean();和 ob_start();語句。
且目錄要有寫權限。


上面的相關思路和函數,請大家認識查看一下函數手冊.

arrow
arrow
    全站熱搜

    yoonow 發表在 痞客邦 留言(0) 人氣()