将当前页面另存为 HTML 到服务器

2022-01-24 00:00:00 file save php html

有人建议用什么方法将当前页面作为 HTML 文件保存到服务器?在这种情况下,还要注意安全性不是问题.

What approach could someone suggest to save the current page as an HTML file to the server? In this case, also note that security is not an issue.

我花了无数时间到处寻找这个,但没有找到任何东西.

I have spent endless hours searching around for this, and have not found a single thing.

非常感谢您的帮助,谢谢!

Your help is much appreciated, thank you!

编辑

感谢大家的帮助,非常感谢.

Thank you all for your help, it was very much appreciated.

推荐答案

如果您的意思是将页面的输出保存在文件中,您可以使用缓冲来实现.您需要使用的函数是 ob_start 和 ob_get_contents.

If you meant saving the output of a page in a file, you can use buffering to do that. The function you need to use are ob_start and ob_get_contents.

<?php
// Start the buffering //
ob_start();
?>
Your page content bla bla bla bla ...

<?php
echo '1';

// Get the content that is in the buffer and put it in your file //
file_put_contents('yourpage.html', ob_get_contents());
?>

这会将页面内容保存在文件yourpage.html中.

This will save the content of the page in the file yourpage.html.

相关文章