阅读并将一系列 HTML 文档与 PHP 相结合


read and combine series of html docs with php

我有一系列的html文档,我想用php组合它们。我需要加载 html 文档的内容并将它们全部显示在一个文档中。我将如何实现这一目标?

忘记requirerequire_onceinclude_once,只使用性能最高的include函数。

include_oncerequire_once是为了防止循环依赖,当然不是HTML;require会抛出致命错误而不是E_WARNING但需要更多时间。

您也可以通过以下方式获取缓冲区中的内容:

$buffer = file_get_contents('index.html');

并决定何时自己回声。或者,您最终可以使用ob_*函数来获取缓冲区:

ob_start():
include('index.html');
$buffer = ob_get_contents();

使用包括,include_once,要求,require_once和添加文件到主文档

编号 : http://php.net/manual/en/function.require-once.php

<?php
$files = array('file1.html','file2.html','file3.html');
foreach($files as $file) require_once $file;

如果要多次包含同一文件,请使用require