0

我有四个页面,我正在尝试压缩并使其更易于维护。我计划使用 PHP 为每个页面的公共部分创建“Web 部件”。问题是 header.php 页面加载并显示了它应该显示的所有内容,但是当我使用 .html 文件时,html 文件不会加载 php 页面。我已经使用了开发者工具并且没有更多错误,还有什么会导致这个问题?我使用了 include 和 require 将单引号更改为 double 以及我能读到或想到的所有内容。我只会粘贴一个 HTML 页面和我的 PHP 页面。

我正在为我的服务器功能使用 QuickPHP

HTML:

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
   <link rel="stylesheet" type="text/css" href="styles.css">
   <script type="text/javascript" src= "clock.js"></script>
   <script type="text/javascript" src= "links.js"></script>
   <meta charset = "utf-8" />
        <title>
      CSE Center for Health Information Technology
    </title>
</head>

<body onload="time()">

<?php require'header.php'; ?>

    <div class = "content">
    <p> 
    <ul>
    <strong>
        <div class = "color">Lastest News!</div> 
    </strong>
    <li> New Positions open at CHIT, click above link to see if you qualify!
 </li>
    <li> New hospital being built in Canton, GA. </li>

<li> CHIT signed agreement with Federal Government to be initiate country wide review
</li>
    </ul>
    </p>

    <p>
    <strong>
        General Information about the Center for Health Information Technology:
    </strong>
    <br />

CHIT was formed to provide certification and compliance  
testing services both to organizations that build and market HIT systems,
and to healthcare providers and hospitals who have implemented HIT systems.
    <br />

Conduct research into the issues that healthcare providers and hospitals face 
in selecting, implementing, and integrating HIT systems.
    <br />

Conduct research and develop tools to strengthen the privacy and security 
of health information, and help people understand their rights and the  resources
available to safeguard their personal health data.

<!-- All three of these came start from http://cse.spsu.edu/chit/index.shtml -->
    <br />
    </p>
    </div>
    <p>
        <h2>Current Time</h2>
        <h2 id="currenttime">now</h2>
    </p>
</body>
</html>

PHP:

<div class = "header">
    <p>
    <a href="http://www.spsu.edu">
<img src="    http://spsu.edu/_resources/images/img_index_logo.png"
    alt="SPSU Home" width="263" height="119" border="0"/></a>
    <br />
    <a href="http://cse.spsu.edu"> SPSU's CSE Home Page <br /> </a>
    </p>

    <p>
    <h1>
        Welcome to the Center for Health Information Technology
    </h1>
    </p>

    <div id="pagelinks">
    <p>
    <strong>
        Page Links!
    </strong>
    <br />
        <select name="links" id="pagelink" onchange="linkchange()">
        <option value = "" >Other Pages</option>
        <option value = "index.html" >Home</option>
        <option value = "faculty.html" >Faculty</option>
        <option value= "survey.html" >Survey</option>
        <option value= "positions.html" >Jobs</option>
        </select>
    </p>
    </div>
</div>
4

2 回答 2

1

服务器将您的代码直接发送到浏览器,因为它看到了 .html 扩展名。如果它是一个 .php 扩展名,服务器就会知道如何处理里面的 php 代码。看看这个解释。 http://php.about.com/od/advancedphp/p/html_php.htm

于 2013-09-26T14:49:23.047 回答
0

.PHPHTML 文件也应该是 PHP 文件,因为您的 HTML 文件包含 PHP 代码段,如果没有提供文件扩展名,则服务器无法解析该代码段。我希望你的问题会得到解决。

无论您使用什么开发工具,都不会在 PHP 代码段中声明任何错误—— <?php require'header.php'; ?>因为它将被视为一个标签,仅此而已。希望这会有所帮助。

于 2013-09-26T15:00:32.947 回答