2010-08-01 120 views
1

試圖打印出一些html表單,但我得到了解析語法錯誤。我相信它卡在SERVER [PHP_SELF]上,但我不確定。我怎樣才能讓它正確回顯?在服務器[PHP_SELF]線發生如何解決解析html代碼時收到的PHP語法錯誤?

錯誤

解析錯誤:語法錯誤,意想不到的T_ENCAPSED_AND_WHITESPACE,期待T_STRING或T_VARIABLE或T_NUM_STRING

function drawbuttons() 
{ 

echo <<<EOT 
<table> 
<tr><td> 
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post"> 
<input type="submit" name="previous" value="Previous" STYLE="font-size:12pt; background-color:00BFFF; color:ffffff">"; 
</form> 
</td> 
<td> 
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post"> 
<input type="submit" name="next" value="Next"STYLE="font-size:12pt; background-color:00BFFF; color:ffffff"> 
</form> 
</td></tr> 
</table> 
EOT; 
} 
+0

您可能需要重新考慮問題的措辭。這聽起來像你想解析你的HTML代碼中的語法錯誤,因爲你不明白它想告訴你什麼。考慮:[HTML:「解析語法錯誤」]沒有「[]」。 – 2010-08-01 20:12:23

+0

你可以顯示確切的錯誤信息=它通常也顯示一個行號,你能告訴我們該代碼片段中的那一行是什麼嗎? – Abel 2010-08-01 20:14:23

回答

3

從手冊上的heredoc syntax

Heredoc text behaves just like a double-quoted string, without the double quotes. This means that quotes in a heredoc do not need to be escaped, but the escape codes listed above can still be used. Variables are expanded, but the same care must be taken when expressing complex variables inside a heredoc as with strings.

這意味着你不能使用PHP打開或關閉標籤,你需要使用的變量正確的語法。在這種情況下,請使用curly brace syntax

echo <<<EOT 
<table> 
<tr><td> 
<form action="{$_SERVER['PHP_SELF']}" method="post"> 
<input type="submit" name="previous" value="Previous" STYLE="font-size:12pt; background-color:00BFFF; color:ffffff">"; 
</form> 
</td> 
<td> 
<form action="{$_SERVER['PHP_SELF']}" method="post"> 
<input type="submit" name="next" value="Next"STYLE="font-size:12pt; background-color:00BFFF; color:ffffff"> 
</form> 
</td></tr> 
</table> 
EOT; 
1

不能使用PHP開始標籤(或短不)在heredocs裏面。

使用,而不是:

<form action="{$_SERVER['PHP_SELF']}" method="post">