"php comment" 在 echo 语句中

"php comment" within an echo statement

如何处理回显命令中间的注释?

此语法给我带来语法错误,但为什么不符合要求?

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

我是否被迫写了 3 个单独的声明?

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

这是因为它解析为:

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

这是一个语法错误,所以是这样的:

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

除了内部字符串文字外,执行时代码中实际上不存在注释。

在评论中包括第二个(或第一个).

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

这将使它解析为:

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