保存为客户端呈现的源代码为.txt文件

Save source code as rendered for client as .txt file

本文关键字:源代码 txt 文件 客户端 保存      更新时间:2023-09-26

我试图保存网页的源代码,因为它是为客户端/用户呈现的。不是因为代码存储在服务器上,而是因为它在脚本在客户端执行之后执行。(如果这有意义的话)。基本上,将源代码视为客户端打开源代码查看器的地方,然后使用PHP将该代码保存为服务器上的.txt文件。我在想一些javascript/HTML5?(当然还有PHP)

基本上你想缓存html输出。您可以使用PHP中的ob_函数:

<?php
ob_start();  //start buffering output
// your html and echo statements
$cachefile = //wherever you want to save it
$fp = fopen($cachefile, 'w');
fwrite($fp, ob_get_contents()); /* save the buffer to cache file */
fclose($fp);
ob_end_flush(); /* Send the buffer to the browser */
?>