主要是如何将整个页面的html代码赋给变量呢?

解决方案 »

  1.   

    <?php
    //读出数据库
    //相关操作
    ?>
    <html>
    <body>
    <?php echo $a;?>……这个中间还有许多html和php混编的内容在里面
    ddd</body>
    </html>
    <?php
    $content = 这里怎么将上面所有的html代码赋给变量呢???
    $file = fopen("a.html","w");
    fwrite($file,$content);
    fclose($file);
    ?>
      

  2.   

    <?php
    //读出数据库
    //相关操作
    function_exists('ob_gzhandler') ? ob_start('ob_gzhandler') : ob_start();//增加这一句$content = ob_get_contents();//
    ?>
      

  3.   


    这样,中间混杂的html代码和输出的php变量,都赋给了$content吗?
    我现在用生成静态文件的方法,不过感觉麻烦了一点,需要将模板文件中的一些变量直接替换。如果能直接将上面所有的html代码直接保存成一个文件,就省事了。
      

  4.   

    ob_start();
    include($file_path);
    $contents = ob_get_contents();
    ob_end_flush();