Well I can't seem to add comments inside a heredoc
block in my foo.php
file:
echo <<<_HEREDOC_FOO
// okay this comment was intended to explain the code below but it
// is showing up on the web page HTML sent to the browser
<form action="foo.php" method="post">
<input type="submit" value="DELETE RECORD" /></form>
_HEREDOC_FOO;
Does the form work, sure (btw the form code above is highly truncated for the sake of my question here).
But the dang comment (okay this comment was..blah blah blah
)
appears in the browser too. It shows up in the
browser just as written above:
// okay this comment was intended to explain the code below but it
// is showing up on the web page HTML sent to the browser
Permutations on the commenting demarcation I've tried:
// <--
// -->
and....
<-- //
--> //
FAIL in both cases to allow me to comment inside heredoc
.
So how the heck can I comment up my code within my heredoc
s?
That's by design. Once you being your heredoc EVERYTHING you type until you end it is treated as being part of one long string. Your best bet would be to break your HEREDOC, put your comment, then start a new echo line
echo <<<_HEREDOC_FOO
text text text
<<<_HEREDOC_FOO;
//Comments
echo <<<_HEREDOC_FOO
text text text
<<<_HEREDOC_FOO;
As someone else mentioned you could do HTML comments, but those will still be visible to anyone who views your source code
You could pass the comment string as a parameter of a variable function.
function heredocComment($comment)
{
return "";
}
$GLOBALS["heredocComment"] = "heredocComment";
echo <<<_HEREDOC_FOO
{$heredocComment("
okay this comment was intended to explain the code below but it
is showing up on the web page html sent to the browser
")}
<form action="foo.php" method="post">
<input type="submit" value="DELETE RECORD" /></form>
_HEREDOC_FOO;
Try this:
echo <<<_HEREDOC_FOO
<!-- okay this comment was intended to explain the code below but it
is showing up on the web page html sent to the browser -->
<form action="foo.php" method="post">
<input type="submit" value="DELETE RECORD" /></form>
_HEREDOC_FOO;
it is now an HTML comment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With