PHP 代码不显示 像相同的 HTML 代码一样


PHP Code not displaying Like same HTML code

我有一个网站,我上传了一个完全由HTML代码(没有PHP)组成的index.html

我将此代码复制到一个PHP文件中index.php,此外,我将标头分离到一个单独的php文件中。当我清理新index.php时,我只是使用了一个include()来包含标题,如下所示:

<? include("TopNote.php"); ?>

因此,index.htmlindex.php 之间的区别在于 HTML 代码直接在 index.html 中,而在 PHP 文件中,它包含在单独的 PHP 文件中。

现在index.php文件给出了一个奇怪的按钮,index.html以我希望它显示的方式显示它。

index.html

<!doctype html>
<html lang="us">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="web/style.css">
  <link href="css/smoothness/jquery-ui-1.10.3.custom.css" rel="stylesheet">
  <style>
    .ui-menu { position: absolute; width: 100px; }
  </style>
  <script src="js/jquery-1.9.1.js"></script>
  <script src="js/jquery-ui-1.10.3.custom.js"></script>
  <script>
    $(function() {
      $( "#menu" ).buttonset();
      $( "#regdialog" ).dialog();
      $( "#buttonregister" ).click(function() {
        $( "#regdialog" ).dialog( "open" );
      });
    });
  </script>
</head>
<body bgcolor="#aaaaaa">
  <img src="example.lorg" alt="" style="padding-left:20px" />
  <div align="right" style="padding-right:20px">
    <div>
      <button id="StaffLogin">Staff Login</button>
      <button id="select">Select an action</button>
    </div>
    <ul>
      <li><a href="#">Log Out</a></li>
      <li id="buttonregister"><a href="#">Register</a></li>
    </ul>
  </div>  
  <form style="margin-top: 1em;">  
    <div id="menu" align="center">
      <input type="radio" id="buttonhome" name="radio" checked="checked"><label for="buttonhome">Home</label>
      <input type="radio" id="buttonforums" name="radio"><label for="buttonforums"><a href="http://example.org">Forums</a></label>
      <input type="radio" id="buttonapply" name="radio"><label for="buttonapply"><a class='fb_iframe' href="http://example.org">Apply</a></label>
      <input type="radio" id="buttonabout" name="radio"><label for="buttonabout">About Us</label>
      <input type="radio" id="select" name="radio">
    </div>
  </form>

  <br />
  <div class="ui-widget">
    <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
      <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
        <strong>Alert:</strong> The Site Is No Where Near Completed, Please go to our <a href="http://example.org/">Forums</a>
      </p>
    </div>
  </div>
  <!-- POP UP -->
  <div id="regdialog" title="Register">
    <form action="#" method="post">
      <div class="ui-widget">
        <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
          <p>
            <span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
            Registrations are not working!
          </p>
        </div>
      </div>
      <h5>Username:</h5>
      <input type="text" name="reg_name">
      <h5>Password:</h5>
      <input type="password" name="reg_pass">
      <h5>Confirm Password:</h5>
      <input type="password" name="reg_pass_conf">
      <input type="submit">
    </form>
  </div>
</body>
</html> 

index.php

<!doctype html>
<html lang="us">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="web/style.css">
  <link href="css/smoothness/jquery-ui-1.10.3.custom.css" rel="stylesheet">
  <script src="js/jquery-1.9.1.js"></script>
  <script src="js/jquery-ui-1.10.3.custom.js"></script>
</head>
<body bgcolor="#aaaaaa">
  <? include("TopNote.php"); ?>
</body>
</html>

topnote.php

<!doctype html>
<html lang="us">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="web/style.css">
  <link href="css/smoothness/jquery-ui-1.10.3.custom.css" rel="stylesheet">
  <style>
    .ui-menu { position: absolute; width: 100px; }
  </style>
  <script src="js/jquery-1.9.1.js"></script>
  <script src="js/jquery-ui-1.10.3.custom.js"></script>
  <script>
    $(function() {
      $( "#menu" ).buttonset();
      $( "#regdialog" ).dialog();
      $( "#buttonregister" ).click(function() {
        $( "#regdialog" ).dialog( "open" );
      });
    });
  </script>
</head>
<body bgcolor="#aaaaaa">
  <img src="example.lorg" alt="" style="padding-left:20px" />
  <div align="right" style="padding-right:20px">
    <div>
      <button id="StaffLogin">Staff Login</button>
      <button id="select">Select an action</button>
    </div>
    <ul>
      <li><a href="#">Log Out</a></li>
      <li id="buttonregister"><a href="#">Register</a></li>
    </ul>
  </div>  
  <form style="margin-top: 1em;">  
    <div id="menu" align="center">
      <input type="radio" id="buttonhome" name="radio" checked="checked"><label for="buttonhome">Home</label>
      <input type="radio" id="buttonforums" name="radio"><label for="buttonforums"><a href="http://example.org">Forums</a></label>
      <input type="radio" id="buttonapply" name="radio"><label for="buttonapply"><a class='fb_iframe' href="http://example.org">Apply</a></label>
      <input type="radio" id="buttonabout" name="radio"><label for="buttonabout">About Us</label>
      <input type="radio" id="select" name="radio">
    </div>
  </form>

  <br />
  <div class="ui-widget">
    <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
      <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
        <strong>Alert:</strong> The Site Is No Where Near Completed, Please go to our <a href="http://example.org/">Forums</a>
      </p>
    </div>
  </div>
  <!-- POP UP -->
  <div id="regdialog" title="Register">
    <form action="#" method="post">
      <div class="ui-widget">
        <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
          <p>
            <span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
            Registrations are not working!
          </p>
        </div>
      </div>
      <h5>Username:</h5>
      <input type="text" name="reg_name">
      <h5>Password:</h5>
      <input type="password" name="reg_pass">
      <h5>Confirm Password:</h5>
      <input type="password" name="reg_pass_conf">
      <input type="submit">
    </form>
  </div>
</body>
</html>

有什么区别,我该如何解决?

<body>标签中不能有<html>标签。您的topnote.php不需要有文档类型,头部和所有这些东西。因为index.php已经定义了html,doctype,head,title等。

因此,您的topnote.php应仅包含以下元素:

<img src="http://destiny-craft.com/img/Logo_Resized.png" alt="" style="padding-left:20px" />
<div align="right" style="padding-right:20px">
  <div>
    <button id="StaffLogin">Staff Login</button>
    <button id="select">Select an action</button>
  </div>
  <ul>
    <li><a href="#">Log Out</a></li>
    <li id="buttonregister"><a href="#">Register</a></li>
  </ul>
</div>  
<form style="margin-top: 1em;">  
   <div id="menu" align="center">
            <input type="radio" id="buttonhome" name="radio" checked="checked"><label for="buttonhome">Home</label>
            <input type="radio" id="buttonforums" name="radio"><label for="buttonforums"><a href="http://forums.destiny-craft.com">Forums</a></label>
            <input type="radio" id="buttonapply" name="radio"><label for="buttonapply"><a class='fb_iframe' href="http://destiny-craft.coffeecup.com/forms/ApplyForm/">Apply</a></label>
        <input type="radio" id="buttonabout" name="radio"><label for="buttonabout">About Us</label>
        <input type="radio" id="select" name="radio">
    </div>
</form>

<br />
<div class="ui-widget">
    <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
            <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
            <strong>Alert:</strong> The Site Is No Where Near Completed, Please go to our <a href="http://forums.destiny-craft.com/">Forums</a></p>
    </div>
</div>



<!-- POP UP -->
<div id="regdialog" title="Register">
<form action="#" method="post">
<div class="ui-widget">
    <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
            <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
            Registrations are not working!</p>
    </div>
</div>
    <h5>Username:</h5>
    <input type="text" name="reg_name">
    <h5>Password:</h5>
    <input type="password" name="reg_pass">
    <h5>Confirm Password:</h5>
    <input type="password" name="reg_pass_conf">
    <input type="submit">
</form>
</div>

您可以将topnote.php <head>标签中的<script>标签移动到topnote.php末尾。将它们放在结束</body>标签之前是有效且更好的做法。这可确保此时加载所有 DOM 元素。

topnote.php不应该

有doctype,html和head,因为你已经在索引中添加了.php

避免使用短标签,这将是XML投诉,如下所示使用

<?php include 'file.php'?>