2013-07-29 69 views
-5

好吧,即時製作登錄系統,出於某種原因,當輸入像這樣即時通訊發佈沒有回聲或打印和下面的腳本顯示本身幫助任何人的問題。如何在php變量中存儲html標記

<?PHP $form = ' 
<form method="POST" action="login.php"> 
<table> 
    <tr> 
     <td>Username:<td> 
     <td><input type="text" name="user"><td> 
    </tr> 
    <tr> 
     <td>Password:<td> 
     <td><input type="password" name="password"><td> 
    </tr> 
    <tr> 
     <td><td> 
     <td><input type="submit" name="loginbtn" value="Login"><td> 
    </tr> 
    <tr> 
     <td><a href="register.php">Register</a><td> 
     <td><a href="forgotpass.php">Forgoten Password</a><td> 
    </tr> 
</table> 
</form>' 
; 
?> 
+5

你已經安裝在Web服務器上PHP?如果這個腳本被執行,什麼都不會發生。您只需將所有HTML分配給變量,然後在不使用該變量的情況下結束腳本。如果你看到所有的代碼,腳本根本不會被執行。你如何測試這個? – GolezTrol

+0

你有什麼問題? –

+1

正如你輸入的那樣,'$ form'只是一個巨大的字符串。 – Sablefoste

回答

2
<?php //Some PHP Code if necessary 
if(true) { //Any html between this brace and the next brace will be included 

?> 

<form method="POST" action="login.php"> 
    <table> 
     <tr> 
      <td>Username:<td><td> 
      <input type="text" name="user"> 
      <td> 
     </tr> 
     <tr> 
      <td>Password:<td><td> 
      <input type="password" name="password"> 
      <td> 
     </tr> 
     <tr> 
      <td><td><td> 
      <input type="submit" name="loginbtn" value="Login"> 
      <td> 
     </tr> 
     <tr> 
      <td><a href="register.php">Register</a><td><td><a href="forgotpass.php">Forgoten Password</a><td> 
     </tr> 
    </table> 
</form> 
<?php 
} //End of if statement. 
else { //This won't be shown, because the if statement is always true 
?> 
<div> 
    This is not displayed 
</div> 

<?php 
} 
?> 
+0

它在if語句中使用,其中else是表單,所以我把它放在var中 –

+0

有更好的方法來做到這一點。你可以在PHP控制語句之間插入html,它將按預期行事。例如,<?php if(true){?>

This will be displayed
<?php} else {?>
This won't be displayed