herdoc:help
Posted: Sat Aug 20, 2005 4:42 am
Code: Select all
echo <<<EOD
<div style='padding:5px; text-align:center; background-color:#000099;color:#FFFFFFF'>
</div>
EOD;A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
echo <<<EOD
<div style='padding:5px; text-align:center; background-color:#000099;color:#FFFFFFF'>
</div>
EOD;http://php.net/manual/en/language.types ... ax.heredocit must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore.
This means the starter and closing identifier of heredoc block not the contents of it.Sami wrote:http://php.net/manual/en/language.types ... ax.heredocit must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore.
Code: Select all
<?php
$str = <<<EOD /* one space after */
<div style="margin-bottom: 12px; padding:5px; text-align:center; background-color:#990000;color:#FFFFFF">
The first
</div>
EOD; /*one space after */
print $str;
print <<<EOD
<div style="margin-bottom: 12px; padding:5px; text-align:center; background-color:#009900;color:#FFFFFF">
The second
</div>
EOD;/*one space before*/
echo <<<EOD
<div style='margin-bottom: 12px; padding:5px; text-align:center; background-color:#000099;color:#FFFFFF'>
and finally the third
</div>
EOD;
?>Code: Select all
$str = <<<EOD /* one space after */
<div style="margin-bottom: 12px; padding:5px; text-align:center; background-color:#990000;color:#FFFFFF">
The first
</div>
EOD; /*one space after */
echo $str;Of course... as the manual page says.wwwapu wrote:This means the starter and closing identifier of heredoc block not the contents of it.
It does without comments and whitespace. Take a look at working exambleraghavan20 wrote:does not work ...
[url=http://us2.php.net/language.types.string]String Syntax for Heredoc[/url] warning wrote: It is very important to note that the line with the closing identifier contains no other characters, except possibly a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs after or before the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by your operating system. This is \r on Macintosh for example.
If this rule is broken and the closing identifier is not "clean" then it's not considered to be a closing identifier and PHP will continue looking for one. If in this case a proper closing identifier is not found then a parse error will result with the line number being at the end of the script.
It is not allowed to use heredoc syntax in initializing class members. Use other string syntaxes instead.