Php 将用于网页的输出重定向到文件

Php 将用于网页的输出重定向到文件,php,Php,我想保存用php生成的网页的html代码。我尝试的基本想法是: ob_start (); $buffered = true; fclose (STDOUT); STDOUT = fopen ("Test/test.htm","wb"); $site_name = 'Cory'; chdir ('..'); include ($site_name.'_V'.$v_defs["sv"].'/Begin.php'); // Draws website

我想保存用php生成的网页的html代码。我尝试的基本想法是:

ob_start (); $buffered = true;

    fclose (STDOUT);
    STDOUT = fopen ("Test/test.htm","wb");

    $site_name = 'Cory'; 
    chdir ('..');
    include ($site_name.'_V'.$v_defs["sv"].'/Begin.php'); // Draws website

    fclose (STDOUT);

我已经尝试了所有我能想到的fopen命令的变体,但是我总是在它上面遇到一个解析错误。

我使用这个函数来获取页面的外部html:

function get_inner_html( $node ) {
    $innerHTML= '';
    $children = $node->childNodes;
    foreach ($children as $child) {
        $innerHTML .= $child->ownerDocument->saveXML( $child );
    }

    return $innerHTML;
} 
function get_html_table($link,$element,$class){
//$data=date("Y-m-d");
$html = file_get_contents($link); //get the html returned from the following url
$poke_doc = new DOMDocument();
libxml_use_internal_errors(false); //disable libxml errors
libxml_use_internal_errors(true);
if(!empty($html)){ //if any html is actually returned
    $poke_doc->loadHTML($html);
    libxml_clear_errors(); //remove errors for yucky html
    $poke_xpath = new DOMXPath($poke_doc);
    $poke_type = $poke_xpath->query("//".$element."[@class='".$class."']");
    $table = "<table>";
    foreach($poke_type as $type){
        $table .= get_inner_html($type);
    }
    $table .= "</table>";
return $table;
}
之后,您可以将$content保存到一个文件中

echo get_html_table('https://www.link.com','table','class');
//first parameter is the link,second: type of dom element, last is the class
$content=get_html_table('https://www.link.com','table','class');