我有一系列的html文档,我想用php组合它们。我需要加载 html 文档的内容并将它们全部显示在一个文档中。我将如何实现这一目标?
忘记require
,require_once
和include_once
,只使用性能最高的include
函数。
include_once
和require_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
。