將當前的 php 網頁輸出

php 一般來說用 ob_* 的函式可以處理當前的檔案輸出

ob_start — Turn on output buffering
ob_get_contents — Return the contents of the output buffer
ob_end_clean — Clean (erase) the output buffer and turn off output buffering

通常是:
ob_start();
echo '要輸出的內容!';
$html1 = ob_get_contents();
echo '還有一些要輸出的內容!';
$html2 = ob_get_contents();
ob_end_clean();
var_dump($html1, $html2);
// 輸出:
   要輸出的內容!
   要輸出的內容! 還有一些要輸出的內容!


但是我用了古早的 SMARTY 這個模版函式,所以
// 原本的顯示內容的網頁
$smarty -> display('show_me_my_page.tpl');
// 抓取原本的顯示內容的網頁的內容
$contents = $smarty -> fetch('show_me_my_page.tpl');
// 把抓取下來的內容存到 show_me_my_page.html
file_put_contents('show_me_my_page.html', $contents);




============================ FAIL ============================
SMARTY:
$contents = $smarty -> display('show_me_my_page.tpl');
file_put_contents('show_me_my_page.html', $contents);

留言

這個網誌中的熱門文章

使用 Excel 計算2個地點之間的直線距離

LINE 儲存的檔案傳到 email 不方便 很不方便 非常不方便 但是有解的筆記

Excel 巨集合併多個 Excel 檔案