插入Php文件

时间:2014-05-19 03:14:26

标签: php html include

我正在学习PHP,现在我正在学习如何添加文件。

然而,

我无法导入例如我的header.php到我的index.php文件中。

我的浏览器卡住了,没有显示任何内容。

我有两个php文件;我试图包含在index.php中的footer.php和header.php

这是我的代码 的index.php

<html>
<head>
    <title><?php echo $page['title'];?></title>
</head>
<body>
<div class="headerr">
<?php
  $page = array();
  include 'footer.php';
?>
</div>
<div>
    <h1>
        Hola
    </h1>
    <article>
        Nulla mauris odio, vehicula in, condimentum sit amet, tempus id, metus. Donec at nisi sit amet felis blandit posuere. Aliquam erat volutpat. Cras lobortis orci in quam porttitor cursus. Aenean dignissim. Curabitur facilisis sem at nisi laoreet placerat. Duis sed ipsum ac nibh mattis feugiat. Proin sed purus. Vivamus lectus ipsum, rhoncus sed, scelerisque sit amet, ultrices in, dolor. Aliquam vel magna non nunc ornare bibendum. Sed libero. Maecenas at est. Vivamus ornare, felis et luctus dapibus, lacus leo convallis diam, eget dapibus augue arcu eget arcu.
    </article>
</div>
<div class="footterr">
<?php
 include 'footer.php';
?>
</div>
</body>
</html>

的header.php

<?php echo '
<!-- top menu bar -->
<table width="90%" border="0" cellspacing="5" cellpadding="5">
    <tr>
        <td><a href="#">Home</a></td>
        <td><a href="#">Site Map</a></td>
        <td><a href="#">Search</a></td>
        <td><a href="#">Help</a></td>
    </tr>
</table>

<!-- header ends -->
' ?>

footer.php

<?php echo'
<!-- footer begins -->
<br />
<center>Your usage of this site is subject to its published <a href="tac.html">terms and conditions</a>. Data is copyright Big Company Inc, 1995-<?php echo date("Y", mktime()); ?></center>

'
?>

2 个答案:

答案 0 :(得分:1)

你在页眉和页脚上忘了半冒号。并且你也不需要在页脚中重新打开php来获取时间函数(你只需要将它附加到文本中)

头:

<?php echo '
<!-- top menu bar -->
<table width="90%" border="0" cellspacing="5" cellpadding="5">
    <tr>
        <td><a href="#">Home</a></td>
        <td><a href="#">Site Map</a></td>
        <td><a href="#">Search</a></td>
        <td><a href="#">Help</a></td>
    </tr>
</table>

<!-- header ends -->
'; ?>

页脚:

    <?php echo'
    <!-- footer begins -->
    <br />
    <center>Your usage of this site is subject to its published <a href="tac.html">terms and conditions</a>. Data is copyright Big Company Inc,  1995-' . date("Y", mktime()) . '
</center>
     ';
        ?>

答案 1 :(得分:1)

您实际上不需要在 footer.php header.php 上使用 echo 。您的 index.php 对我来说很好。

<强> footer.php

<!-- footer begins -->
<br />
<center>Your usage of this site is subject to its published <a href="tac.html">terms and conditions</a>. Data is copyright Big Company Inc, 1995-<?php echo date("Y", mktime()); ?></center>

<强>的header.php

<!-- top menu bar -->
<table width="90%" border="0" cellspacing="5" cellpadding="5">
  <tr>
    <td><a href="#">Home</a></td>
    <td><a href="#">Site Map</a></td>
    <td><a href="#">Search</a></td>
    <td><a href="#">Help</a></td>
  </tr>
</table>
<!-- header ends -->