在PHP中使用Include函数,完全忽略它

时间:2015-07-12 19:03:18

标签: php html web

所以我目前有两个文件。 index.php 2. header.php

我希望将头文件“包含”在我的所有其他网页中,因此为了实现这一点,我只需编辑该文件即可对页眉和页脚进行网络范围的更新。我的网站支持PHP,我正在运行PHP 5.4 FASTCGI。此外,所有文件都是通过filezilla上传的,所以我知道他们在那里。以及HTML工作,而不是放在include函数中。当我把它放入其中似乎只是表现为没有“包含”并继续生成网站的其余部分,而不是抛出错误。

以下是我的文件构成,它们都位于同一目录中。

  1. index.php(只是复制了该函数,因为其他一切正常,如果需要我可以发布休息,但它现在很大而且很通用。)
  2. <?php include'header.php';?>        

    1. 的header.php
    2. <?php '	
               <!-- Header Start -->
               <header id="header">
                  <!-- Header Top Bar Start -->
                  <div class="top-bar">
                     <div class="slidedown collapse">
                        <div class="container">
                           <div class="phone-email pull-left">
                              <a><i class="fa fa-phone"></i> Call Us : +880 111-111-111</a>
                              <a href="support@fifothemes.com"><i class="fa fa-envelope"></i> Email : support@fifothemes.com</a>
                           </div>
                           <div class="pull-right">
                              <ul class="social pull-left">
                                 <li class="facebook"><a href="#"><i class="fa fa-facebook"></i></a></li>
                                 <li class="twitter"><a href="#"><i class="fa fa-twitter"></i></a></li>
                                 <li class="dribbble"><a href="#"><i class="fa fa-dribbble"></i></a></li>
                                 <li class="linkedin"><a href="#"><i class="fa fa-linkedin"></i></a></li>
                                 <li class="rss"><a href="#"><i class="fa fa-rss"></i></a></li>
                              </ul>
                              <div id="search-form" class="pull-right">
                                 <form action="#" method="get">
                                    <input type="text" class="search-text-box" placeholder="Search...">
                                 </form>
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
                  <!-- Header Top Bar End -->
                  <!-- Main Header Start -->
                  <div class="main-header">
                     <div class="container">
                        <!-- TopNav Start -->
                        <div class="topnav navbar-header">
                           <a class="navbar-toggle down-button" data-toggle="collapse" data-target=".slidedown">
                           <i class="fa fa-angle-down fa fa-current"></i>
                           </a> 
                        </div>
                        <!-- TopNav End -->
                        <!-- Logo Start -->
                        <div class="logo pull-left">
                           <h1>
                              <a href="index.html">
                              <img src="img/logo.png" alt="pixma" width="125" height="60">
                              </a>
                           </h1>
                        </div>
                        <!-- Logo End -->
                        <!-- Mobile Menu Start -->
                        <div class="mobile navbar-header">
                           <a class="navbar-toggle" data-toggle="collapse" href=".navbar-collapse">
                           <i class="fa fa-bars fa-2x"></i>
                           </a> 
                        </div>
                        <!-- Mobile Menu End -->
                        <!-- Menu Start -->
                        <nav class="collapse navbar-collapse menu">
                           <ul class="nav navbar-nav sf-menu">
                              <li>
                                 <a id="current" href="index.html">
                                 Home
                                 <span class="sf-sub-indicator">
                                 <i class="fa fa-angle-down "></i>
                                 </span>
                                 </a>
                                 <ul>
                                    <li><a href="index-2.html" class="sf-with-ul">Home 2</a></li>
                                    <li><a href="index-3.html" class="sf-with-ul">Home 3</a></li>
                                    <li><a href="index-4.html" class="sf-with-ul">Home 4</a></li>
                                    <li><a href="index-nivo.html" class="sf-with-ul">Nivo Slider</a></li>
                                 </ul>
                              </li>
                              <li>
                                 <a href="#" class="sf-with-ul">
                                 Features 
                                 <span class="sf-sub-indicator">
                                 <i class="fa fa-angle-down "></i>
                                 </span>
                                 </a>
                                 <ul>
                                    <li><a href="shortcodes.html" class="sf-with-ul">Shortcodes</a></li>
                                    <li><a href="icons.html" class="sf-with-ul">Icons</a></li>
                                    <li><a href="pricing-table.html" class="sf-with-ul">Pricing Tables</a></li>
                                    <li>
                                       <a href="#" class="sf-with-ul"> 
                                       Third Level Menu 
                                       <span class="sf-sub-indicator pull-right">
                                       <i class="fa fa-angle-right "></i>
                                       </span>
                                       </a>
                                       <ul>
                                          <li><a href="#" class="sf-with-ul">Menu Item</a></li>
                                          <li><a href="#" class="sf-with-ul">Menu Item</a></li>
                                          <li><a href="#" class="sf-with-ul">Menu Item</a></li>
                                       </ul>
                                    </li>
                                 </ul>
                              </li>
                              <li>
                                 <a href="#" class="sf-with-ul">
                                 Pages
                                 <span class="sf-sub-indicator">
                                 <i class="fa fa-angle-down "></i>
                                 </span>
                                 </a>
                                 <ul>
                                    <li><a href="about.html" class="sf-with-ul">About Us</a></li>
                                    <li><a href="services.html" class="sf-with-ul">Services</a></li>
                                    <li><a href="testimonials.html" class="sf-with-ul">Testimonials</a></li>
                                    <li><a href="full-width.html" class="sf-with-ul">Full Width Page</a></li>
                                    <li><a href="page-left-sidebar.html" class="sf-with-ul">Left Sidebar</a></li>
                                    <li><a href="page-right-sidebar.html" class="sf-with-ul">Right Sidebar</a></li>
                                    <li><a href="page-left-navigation.html" class="sf-with-ul">Left Navigation</a></li>
                                    <li><a href="page-right-navigation.html" class="sf-with-ul">Right Navigation</a></li>
                                    
                                    <li><a href="faq.html" class="sf-with-ul">FAQ</a></li>
                                    <li><a href="page-404.html" class="sf-with-ul">404 Page</a></li>
      							  <li><a href="search-results.html" class="sf-with-ul">Search Results</a></li>
                                    <li><a href="sitemap.html" class="sf-with-ul">Sitemap</a></li>
                                 </ul>
                              </li>
                              <li>
                                 <a href="#" class="sf-with-ul">
                                 Portfolio
                                 <span class="sf-sub-indicator">
                                 <i class="fa fa-angle-down "></i>
                                 </span>
                                 </a>
                                 <ul>
                                    <li><a href="portfolio-two.html" class="sf-with-ul">2 Column</a></li>
                                    <li><a href="portfolio-three.html" class="sf-with-ul">3 Column</a></li>
                                    <li><a href="portfolio-four.html" class="sf-with-ul">4 Column</a></li>
                                    <li><a href="portfolio-single.html" class="sf-with-ul">Single Item Page</a></li>
                                    <li><a href="portfolio-single-big.html" class="sf-with-ul">Single Large Item Page</a></li>
                                 </ul>
                              </li>
                              <li>
                                 <a href="#" class="sf-with-ul">
                                 Blog
                                 <span class="sf-sub-indicator">
                                 <i class="fa fa-angle-down "></i>
                                 </span>
                                 </a>
                                 <ul>
                                    <li><a href="blog-left-sidebar.html" class="sf-with-ul">Left Sidebar Blog</a></li>
                                    <li><a href="blog-right-sidebar.html" class="sf-with-ul">Right Sidebar Blog</a></li>
                                    <li><a href="blog-small.html" class="sf-with-ul">Small Blog</a></li>
                                    <li><a href="single-post.html" class="sf-with-ul">Single Post</a></li>
                                 </ul>
                              </li>
                              <li><a href="#">
                                  Contact
                                  <span class="sf-sub-indicator">
                                    <i class="fa fa-angle-down"></i>
                                  </span>
                                  </a>
                                  <ul>
                                    <li><a href="contact.html" class="sf-with-ul">Contact</a></li>
                                    <li><a href="contact-2.html" class="sf-with-ul">Contact 2</a></li>
                                  </ul>
                               </li>
                           </ul>
                        </nav>
                        <!-- Menu End --> 
                     </div>
                  </div>
                  <!-- Main Header End -->
               </header>
               <!-- Header End --> 
      ';?>

3 个答案:

答案 0 :(得分:0)

Remove <?php and ?> tags, inside the script only have html code.

您的脚本仅限:

'long string';

php中的引号之间的字符串没有生成任何输出,你需要删除php标签或在字符串之前添加“print”函数。

答案 1 :(得分:0)

要么在你之后使用eco

<?PHP  //any php code. ?>

  <!-- Header Start -->
         <header id="header">
            <!-- Header Top Bar Start -->
            <div class="top-bar">
               <div class="slidedown collapse">
                  <div class="container">
                     <div class="phone-email pull-left">
                        <a><i class="fa fa-phone"></i> Call Us : +880 111-111-111</a>
                        <a href="support@fifothemes.com"><i class="fa fa-envelope"></i> Email : support@fifothemes.com</a>
                     </div>
                     <div class="pull-right">
                        <ul class="social pull-left">
                           <li class="facebook"><a href="#"><i class="fa fa-facebook"></i></a></li>
                           <li class="twitter"><a href="#"><i class="fa fa-twitter"></i></a></li>
                           <li class="dribbble"><a href="#"><i class="fa fa-dribbble"></i></a></li>
                           <li class="linkedin"><a href="#"><i class="fa fa-linkedin"></i></a></li>
                           <li class="rss"><a href="#"><i class="fa fa-rss"></i></a></li>
                        </ul>
                        <div id="search-form" class="pull-right">
                           <form action="#" method="get">
                              <input type="text" class="search-text-box" placeholder="Search...">
                           </form>
                        </div>
                     </div>
                  </div>
               </div>
            </div>
            <!-- Header Top Bar End -->
            <!-- Main Header Start -->
            <div class="main-header">
               <div class="container">
                  <!-- TopNav Start -->
                  <div class="topnav navbar-header">
                     <a class="navbar-toggle down-button" data-toggle="collapse" data-target=".slidedown">
                     <i class="fa fa-angle-down fa fa-current"></i>
                     </a> 
                  </div>
                  <!-- TopNav End -->
                  <!-- Logo Start -->
                  <div class="logo pull-left">
                     <h1>
                        <a href="index.html">
                        <img src="img/logo.png" alt="pixma" width="125" height="60">
                        </a>
                     </h1>
                  </div>
                  <!-- Logo End -->
                  <!-- Mobile Menu Start -->
                  <div class="mobile navbar-header">
                     <a class="navbar-toggle" data-toggle="collapse" href=".navbar-collapse">
                     <i class="fa fa-bars fa-2x"></i>
                     </a> 
                  </div>
                  <!-- Mobile Menu End -->
                  <!-- Menu Start -->
                  <nav class="collapse navbar-collapse menu">
                     <ul class="nav navbar-nav sf-menu">
                        <li>
                           <a id="current" href="index.html">
                           Home
                           <span class="sf-sub-indicator">
                           <i class="fa fa-angle-down "></i>
                           </span>
                           </a>
                           <ul>
                              <li><a href="index-2.html" class="sf-with-ul">Home 2</a></li>
                              <li><a href="index-3.html" class="sf-with-ul">Home 3</a></li>
                              <li><a href="index-4.html" class="sf-with-ul">Home 4</a></li>
                              <li><a href="index-nivo.html" class="sf-with-ul">Nivo Slider</a></li>
                           </ul>
                        </li>
                        <li>
                           <a href="#" class="sf-with-ul">
                           Features 
                           <span class="sf-sub-indicator">
                           <i class="fa fa-angle-down "></i>
                           </span>
                           </a>
                           <ul>
                              <li><a href="shortcodes.html" class="sf-with-ul">Shortcodes</a></li>
                              <li><a href="icons.html" class="sf-with-ul">Icons</a></li>
                              <li><a href="pricing-table.html" class="sf-with-ul">Pricing Tables</a></li>
                              <li>
                                 <a href="#" class="sf-with-ul"> 
                                 Third Level Menu 
                                 <span class="sf-sub-indicator pull-right">
                                 <i class="fa fa-angle-right "></i>
                                 </span>
                                 </a>
                                 <ul>
                                    <li><a href="#" class="sf-with-ul">Menu Item</a></li>
                                    <li><a href="#" class="sf-with-ul">Menu Item</a></li>
                                    <li><a href="#" class="sf-with-ul">Menu Item</a></li>
                                 </ul>
                              </li>
                           </ul>
                        </li>
                        <li>
                           <a href="#" class="sf-with-ul">
                           Pages
                           <span class="sf-sub-indicator">
                           <i class="fa fa-angle-down "></i>
                           </span>
                           </a>
                           <ul>
                              <li><a href="about.html" class="sf-with-ul">About Us</a></li>
                              <li><a href="services.html" class="sf-with-ul">Services</a></li>
                              <li><a href="testimonials.html" class="sf-with-ul">Testimonials</a></li>
                              <li><a href="full-width.html" class="sf-with-ul">Full Width Page</a></li>
                              <li><a href="page-left-sidebar.html" class="sf-with-ul">Left Sidebar</a></li>
                              <li><a href="page-right-sidebar.html" class="sf-with-ul">Right Sidebar</a></li>
                              <li><a href="page-left-navigation.html" class="sf-with-ul">Left Navigation</a></li>
                              <li><a href="page-right-navigation.html" class="sf-with-ul">Right Navigation</a></li>

                              <li><a href="faq.html" class="sf-with-ul">FAQ</a></li>
                              <li><a href="page-404.html" class="sf-with-ul">404 Page</a></li>
                              <li><a href="search-results.html" class="sf-with-ul">Search Results</a></li>
                              <li><a href="sitemap.html" class="sf-with-ul">Sitemap</a></li>
                           </ul>
                        </li>
                        <li>
                           <a href="#" class="sf-with-ul">
                           Portfolio
                           <span class="sf-sub-indicator">
                           <i class="fa fa-angle-down "></i>
                           </span>
                           </a>
                           <ul>
                              <li><a href="portfolio-two.html" class="sf-with-ul">2 Column</a></li>
                              <li><a href="portfolio-three.html" class="sf-with-ul">3 Column</a></li>
                              <li><a href="portfolio-four.html" class="sf-with-ul">4 Column</a></li>
                              <li><a href="portfolio-single.html" class="sf-with-ul">Single Item Page</a></li>
                              <li><a href="portfolio-single-big.html" class="sf-with-ul">Single Large Item Page</a></li>
                           </ul>
                        </li>
                        <li>
                           <a href="#" class="sf-with-ul">
                           Blog
                           <span class="sf-sub-indicator">
                           <i class="fa fa-angle-down "></i>
                           </span>
                           </a>
                           <ul>
                              <li><a href="blog-left-sidebar.html" class="sf-with-ul">Left Sidebar Blog</a></li>
                              <li><a href="blog-right-sidebar.html" class="sf-with-ul">Right Sidebar Blog</a></li>
                              <li><a href="blog-small.html" class="sf-with-ul">Small Blog</a></li>
                              <li><a href="single-post.html" class="sf-with-ul">Single Post</a></li>
                           </ul>
                        </li>
                        <li><a href="#">
                            Contact
                            <span class="sf-sub-indicator">
                              <i class="fa fa-angle-down"></i>
                            </span>
                            </a>
                            <ul>
                              <li><a href="contact.html" class="sf-with-ul">Contact</a></li>
                              <li><a href="contact-2.html" class="sf-with-ul">Contact 2</a></li>
                            </ul>
                         </li>
                     </ul>
                  </nav>
                  <!-- Menu End --> 
               </div>
            </div>
            <!-- Main Header End -->
         </header>
         <!-- Header End --> 

答案 2 :(得分:0)

当你想运行php时,你的header.php文件应该只打开<?php标签。如果您只是添加一些html,请将其留在<?php标记之外。当您想要运行php脚本时,请打开<?php标签。像这样:

<!-- Header Start -->
     <header id="header">
        <!-- Header Top Bar Start -->
        <div class="top-bar">
           <div class="slidedown collapse">
              <div class="container">
                 <div class="phone-email pull-left">
                    <a><i class="fa fa-phone"></i> Call Us : +880 111-111-111</a>
                    <a href="support@fifothemes.com"><i class="fa fa-envelope"></i> Email : support@fifothemes.com</a>
                 </div>
<?php echo 'This is a php script!'; ?>
                 <div class="pull-right">
                    <ul class="social pull-left">
                       <li class="facebook"><a href="#"><i class="fa fa-facebook"></i></a></li>
                       <li class="twitter"><a href="#"><i class="fa fa-twitter"></i></a></li>
                       <li class="dribbble"><a href="#"><i class="fa fa-dribbble"></i></a></li>
                       <li class="linkedin"><a href="#"><i class="fa fa-linkedin"></i></a></li>
                       <li class="rss"><a href="#"><i class="fa fa-rss"></i></a></li>
                    </ul>