How can I solve a PHP syntax error that I receive when parsing html code?
Trying to print out some html forms but I get a parsing syntax error. I believe it gets stuck on the SERVER[PHP_SELF] but I'm not sure. How can I get this to echo correctly?
Error occurs on the SERVER[PHP_SELF] line
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
function drawbuttons()
{
echo <&开发者_运维百科lt;<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;
}
From the manual on the 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.
That means you can’t use PHP open or close tags and you need to use the proper syntax for variables. In this case use the 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;
You can't use PHP opening tags (short or not) inside heredocs.
Use instead:
<form action="{$_SERVER['PHP_SELF']}" method="post">
精彩评论