I have the following code to display form by a variable using heredoc. I get the following error;
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\PHP\2000.php on line 38
Line 38 is: <form method="POST" action="$_SERVER['PHP_SELF']">
<?php
if ( !$_POST ){
$display_block = <<<EOB
<form method="POST" action="$_SERVER['PHP_SELF']">
<p>
<label for="email"> Your E-Mail Address: </label> <br/>
<input type="email" id="email" name="email" size="40" maxlength="150"/>
</p>
<fieldset>
<legend> Action: </legend>
<input type="radio" id="action_sub" name="action" value="sub" checked/>
<label for="action_sub"> Subscribe </label> <br>
<input type="radio" id="action_unsub" name="action" value="unsub"/>
<label for="action_unsub"> Unsubscribe </label
</fieldset>
<button type="submit" name="btnSubmit" value="Send"> Submit </button>
</form>
EOB; //closing delimiter must start with no spaces nor tabs infront of it.
}
echo $display_block;
?>
My questions are;
- In this case, heredoc acts exactly as $display_block = " string inside double quotes " ? So that should I use { } as
action="{$_SERVER['PHP_SELF']}
in order to wrap array item in double quotes?
But when I use that, I get a new error;
Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\PHP\2000.php on line 59
Line 59 is: ?>
- Why cannot I use like this for the action attribute?
action = “<?php echo $_SERVER[‘PHP_SELF’]; ?>”