Home  >  Article  >  Backend Development  >  Static page - looking for a php static web page generation solution

Static page - looking for a php static web page generation solution

WBOY
WBOYOriginal
2016-10-22 00:14:09897browse

I want to add a function to export static web pages to my website. Is there any good solution to quickly export it?

Reply content:

I want to add a function to export static web pages to my website. Is there any good solution to quickly export it?

Isn’t there a file_put_content() function?

You need to use the ob_start() series of methods,

Using curl file_get_contentS and other simulated requests will be very inefficient, and various frameworks are implemented using ob

It’s difficult to type on the mobile phone, I don’t know for sure

You can take a look at the Output Control function in php

Why not use wget to directly grab the mirror and download it as a tgz package

`ob_start();
//Template processing
//echo template content
$content = ob_get_contents();
ob_end_clean();
file_put_contents('./demo.html', $content);`

It can also be implemented using smart templates, as shown below:

<code><?php
require('smarty/Smarty.class.php');
$t = new Smarty;
$t->assign("title","Hello World!");
$content = $t->fetch("templates/index.htm");
//这里的 fetch() 就是获取输出内容的函数,现在$content变量里面,就是要显示的内容了
$fp = fopen("archives/2005/05/19/0001.html", "w");
fwrite($fp, $content);
fclose($fp);
?></code>

It is also very easy to use.

<code><?php
/* 在这里数据库增删改查之前对缓存进行过期判断和应用 */
$app['data'] = db_crud();
$view = render('index.php');
function render($template) {
    global $app;
    ob_end_clean();
    ob_start();
    require APP_ROOT.'/view/'.$template; //模板里会用到数据$app['data']
    $html = ob_get_contents();
    ob_end_clean();
    ob_start();
    /* 在这里把 ob_get_contents 拿到的字符串 file_put_contents 写入文件系统 */
    return $html;
}</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn