如何从同一文件夹上的外部文件中回显html片段?

时间:2013-04-03 13:48:49

标签: php echo

我想创建更清晰的html文档/模板,它使用echo命令来调用html / scripts。

虽然......我无法找到如何让它发挥作用。

我想要达到的文件就像

<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和php文档(?&gt;)中编写了一段HTML,只是为了尝试,如果这有任何区别..)

但是..你们都知道:这不起作用。

所以答案很简单:

我如何'回显'外部文件中的一块/一切,如上所述:回显'portfolio.html'内容。

谢谢!

P.S。我认为echo是'粘贴'外部编码的最佳选择,但是如果你有更好,更简单,更多SEO解决方案:做我的客人!

2 个答案:

答案 0 :(得分:4)

使用包含

<html>
    <head>
    </head>
    <body>
        <?php
            include 'header.html';
            include 'container.html';
            include 'footer.html';
        ?>
    </body>
</html>

http://php.net/manual/en/function.include.php

答案 1 :(得分:0)

无法回显文件。 使用

require_once(dirname(__FILE__).'/header.html');
require_once(dirname(__FILE__).'/container.html');
require_once(dirname(__FILE__).'/footer.html');