我想在网站中加个导出静态网页的功能,有什么好的方案可以快速导出呢?
我想在网站中加个导出静态网页的功能,有什么好的方案可以快速导出呢?
不是有个file_put_content()的函数吗?
需要用到ob_start() 系列方法,
用curl file_get_contentS 等模拟请求,都将非常低效,各种框架都用ob实现
立即学习“PHP免费学习笔记(深入)”;
手机端打码字难,不详说了
可以看一下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>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号