如何在另一个php文件中包含带有bootstrap内容的php文件

时间:2016-11-15 11:26:34

标签: php jquery html css

我在另一个php文件中包含带有导航栏的php文件时遇到问题。

这是导航文件:

<?php echo "
<html>
<head>
<nav class = "navbar navbar-default navbar-fixed-top " role = "navigation">
<div class = "container-fluid">

  <div class = "navbar-header navbar-right">
    <ul class = "nav navbar-nav">
      <li><a href = "index.php"> About Me </a></li>
      <li><a href = "contact.php"> Contacts </a></li>
      <li><a href = "skills.php"> Skills </a></li>
      <li><a href = "portfolio.php"> Portfolio </a></li>
      <li><a href = "case_studies.php"> Case Studies</a></li>
      <li><a href = "resume.php"> Resume </a></li>
      <li><a href = "extras.php"> Extras</a></li>
    </ul>
  </div>
  </div>
</nav>
</head>
<script src = "js/bootstrap.min.js"></script>
<script src = "js/jquery.min.js"></script>
</html>
" ?>

我在index.php文件中有这一行

<?php 
include"navigation.php"; 
?>

我检查了文件的引用,所有引用似乎都没问题。

3 个答案:

答案 0 :(得分:0)

为什么要关闭导航文件中的HTML标记?

最好有一个&#39;主人&#39;应用程序模板,其中包含html标记,头部和正文,然后在正文中包含底部的脚本,并使用PHP标记包含导航栏。

答案 1 :(得分:0)

<?php try{
            if( !file_exists("navigation.php") )
            {  throw new Exception("Unable to include resources header");  }
            else{  require_once("navigation.php");  }
            }catch(Exception $e){
                echo $e->getMessage();
                exit;
            }
?>

请试试这个肯定会有效。这是我的工作。

答案 2 :(得分:0)

“应该是'

        <?php echo '
        <html>
        <head>
        <nav class = "navbar navbar-default navbar-fixed-top " role = "navigation">
        <div class = "container-fluid">

          <div class = "navbar-header navbar-right">
            <ul class = "nav navbar-nav">
              <li><a href = "index.php"> About Me </a></li>
              <li><a href = "contact.php"> Contacts </a></li>
              <li><a href = "skills.php"> Skills </a></li>
              <li><a href = "portfolio.php"> Portfolio </a></li>
              <li><a href = "case_studies.php"> Case Studies</a></li>
              <li><a href = "resume.php"> Resume </a></li>
              <li><a href = "extras.php"> Extras</a></li>
            </ul>
          </div>
          </div>
        </nav>
        </head>
        <script src = "js/bootstrap.min.js"></script>
        <script src = "js/jquery.min.js"></script>
        </html>
        ';?>

包含文件

<?php
include 'navigation.php';
?>