标题&页脚php调用html网站无法正常工作

时间:2016-06-01 04:47:44

标签: php html css

我的header.php和footer.php文件没有被index.html文件获取。我搜索了Stackoverflow,并遵循了不同的变体,例如<?php include("header.php"); ?>$("#header").load("header.html");,但它仍然不起作用。我的代码如下,有人可以告诉我我做错了吗?

的header.php

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>aaaa</title>
    <meta name="description" content="aaaa.">
    <link rel='shortcut icon' href='myfavicon.ico' type='image/x-icon'/ >

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/custom.css" rel="stylesheet">
    <!-- Custom Fonts -->
    <link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,700' rel='stylesheet' type='text/css'>
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    </head>

<header>
      <!-- HEADER -->
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
        <a class="navbar-brand" href="index.html">
            <img alt="aaaa" src="images/aa.png" height="30px">
        </a>
        </div>     
      </div><!--END CONTAINER FLUID-->
    </nav>

的index.html

<?php include("header.php"); ?>
<div class="container-fluid">
            <div class="row feature">
                <img src="images/Homepage%20Banner.jpg" class="img-responsive" alt="aaaa">
                <div class="feature-text col-xs-12 col-md-8 col-lg-6 col-md-offset-2 col-lg-offset-3">
                    <p>aaaaa</p>
                </div><!--END FEATURE TXT-->
            </div><!--END ROW FEATURES-->

3 个答案:

答案 0 :(得分:1)

PHP代码位于扩展名为.php的文件中。 在Header.php中,如果您没有PHP代码,那么只需将其写入.HTML扩展名,即Header.html 因此,请将index.html重命名为index.php

答案 1 :(得分:0)

而不是index.html更改index.php。 通过使用php文件,我们可以包含其他php文件。

答案 2 :(得分:0)

您无法在.html文件中运行PHP,因为服务器无法将其识别为有效的PHP扩展名,除非您告诉它。

这里<?php include("header.php") ?>是HTML文件中的php代码。

您需要将index.html更改为index.php