簡體   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