静态页面 - 求php静态网页生成方案

WBOY
发布: 2016-10-22 00:14:09
原创
866 人浏览过

我想在网站中加个导出静态网页的功能,有什么好的方案可以快速导出呢?

回复内容:

我想在网站中加个导出静态网页的功能,有什么好的方案可以快速导出呢?

不是有个file_put_content()的函数吗?

需要用到ob_start() 系列方法,

用curl file_get_contentS 等模拟请求,都将非常低效,各种框架都用ob实现

手机端打码字难,不详说了

可以看一下php中的Output Control函数

何不用wget直接抓个mirror出来然后打个tgz包下载

`ob_start();
//模板处理
//echo 模板内容
$content = ob_get_contents();
ob_end_clean();
file_put_contents('./demo.html', $content);`

也可以用smart模板实现,如下所示:

<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>
登录后复制

使用也很简便。

<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></code>
登录后复制
相关标签:
php
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!