繁体   English   中英

最终输出混乱了一些基本的PHP

[英]Final Output Messed up Some Basic PHP

我有以下测试文档:

<!DOCTYPE html>
<html>
<head>
<title>A Word finding Tutorial
</title>
</head>
<body>
<?php
include "inc/header.php";
?>
<form action="test3.php" method="GET">
Text Field: <br> <textarea name="long_text" rows="4" cols="50">Enter the Para Here.</textarea>
<br>
Finding : <br> <input type="text" name="find" value="Enter the word to find">
<input type="submit" value="Submit"> 
Result:
</body>
</html>

现在header.php文件有点像这样:

<html>
<head>
<style>
img#imgheader {margin:5px;padding:10px 5px;}
div#header {background-color:#ccff33;}
</style>
</head>
<body>
<div id="header" style="text-align: center;">
<img id="imgheader" src="\test\img\trial.png" alt="header" height="30px" width="60px">
</div>
</body>
</html>

现在我的问题是,当输出它时,基本上就像搞砸了,就像我看到的test.php最终输出的源代码如下:-

<!DOCTYPE html>
<html>
<head>
<title>A Word finding Tutorial
</title>
</head>
<body>
<html>
<head>
<style>
img#imgheader {margin:5px;padding:10px 5px;}
div#header {background-color:#ccff33;}
</style>
</head>
<body>
<div id="header" style="text-align: center;">
<img id="imgheader" src="\test\img\trial.png" alt="header" height="30px" width="60px">
</div>
</body>
</html>
<form action="test3.php" method="GET">
Text Field: <br> <textarea name="long_text" rows="4" cols="50">Enter the Para Here.</textarea>
<br>
Finding : <br> <input type="text" name="find" value="Enter the word to find">
<input type="submit" value="Submit"> 
Result:
</body>
</html>

如您所见,最终的输出就像HTML页面中的Html页面一样。 因此,基本上它不会通过w3进行优化,但将来可能会产生错误。 我的问题是这样做的正确方法,如果不能,那么怎么写也不会最终弄乱。

似乎很清楚,您包含的文件中不应包含这些标头。 我建议你先创建一个css文件

mystyle.css

#header {text-align: center;}
img#imgheader {margin:5px;padding:10px 5px;}
div#header {background-color:#ccff33;}

然后header.php应该看起来像(注意您的斜杠将不起作用),

<link rel="stylesheet" type="text/css" href="mystyle.css" />
<div id="header">
  <img id="imgheader" src="/test/img/trial.png" alt="header" height="30" width="60">
</div>

当前,它包含重复的html标签,因为您将它们包含在header.php

这是不正确的HTML。 您必须将header.php文件编辑为:

<?php     

function returnHead() { ?> 
    <style>
    img#imgheader {margin:5px;padding:10px 5px;}
    div#header {background-color:#ccff33;}
    </style> 
<?php }


function returnBody() { ?> 
    <div id="header" style="text-align: center;">
    <img id="imgheader" src="\test\img\trial.png" alt="header" height="30px" width="60px">
    </div> 
<?php } 

?>

然后将您的测试文档转到:

<?php
include "inc/header.php";
?>
<!DOCTYPE html>
<html>
<head>
<title>A Word finding Tutorial</title>
<?php returnHead(); ?>
</head>
<body>
<?php returnBody(); ?>
<form action="test3.php" method="GET">
Text Field: <br> <textarea name="long_text" rows="4" cols="50">Enter the Para Here.</textarea>
<br>
Finding : <br> <input type="text" name="find" value="Enter the word to find">
<input type="submit" value="Submit"> 
Result:
</body>
</html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM