0

How can I handle comments in the middle of an echo command?

This syntax is getting me a syntax error but why is not compliant?

<?
echo "Print this " . /*but not this*/ . " and this\n";
?>

Am I forced to write 3 separate statements?

<?
echo "Print this "
/*but not this*/
echo " and this\n";
?>
1

2 Answers 2

4

Its because it resolves to:

echo "Print this " .  . " and this\n";

Which is a syntax error, so is this:

echo "Print this " echo " and this\n";

With the exception of inside string literals, comments effectively don't exist in the code upon execution.

Sign up to request clarification or add additional context in comments.

1 Comment

very clear! This is working: <? echo "Print this " . /*but not this*/ " and this\n"; ?>
2

Include the second (or the first) . in the comment:

echo "Print this " . /*but not this .*/ " and this\n";

That will make it resolve to:

echo "Print this " . " and this\n";

1 Comment

This still works. Even works if it's multiple lines and the . /* comment . */ is on a new line. Cool stuff. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.