我想创建一个更干净的html文档/模板,它使用echo命令来调用html/脚本的片段。
虽然. .我不知道怎样使它工作。
我要访问的文档是
<html>
<head>
</head>
<body>
<?php
echo 'header.html';
echo 'container.html';
echo 'footer.html';
?>
这样我就可以在一个单独的文档中编辑网站的每个部分,而不是把网站的所有部分放在一个整体中。
<?php
$myString = 'include(portfolio.php); ';
echo $myString;
echo file_get_html('portfolio.php');
echo file_get_html('portfolio.html');
?>
(为了尝试,我已经把一块HTML只编码在HTML和php文档(?>)只是为了尝试,如果这是任何差异…)
但. .你们可能都知道:这行不通。
所以你的答案尽可能简单:
如何在外部文件中"回显"一段/所有内容,如上面所示:
谢谢!
注。我认为echo是我"粘贴"外部代码的最佳选择,但如果你有一个更好,更容易,更SEO的解决方案:请接受我的邀请!
Use includes
<html>
<head>
</head>
<body>
<?php
include 'header.html';
include 'container.html';
include 'footer.html';
?>
</body>
</html>
http://php.net/manual/en/function.include.php 无法回显文件。使用
require_once(dirname(__FILE__).'/header.html');
require_once(dirname(__FILE__).'/container.html');
require_once(dirname(__FILE__).'/footer.html');