我正在使用EOD从字符串中转义引号和单引号,但我想用新行显示字符串。
这是我的 php 代码:
echo <<<'EOT'
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should not print a capital 'A': 'x41
EOT;
事实证明,结果如下(连续线):
我的名字是"$name"。我正在打印一些 $foo->foo。' 现在,我正在打印一些 {$foo->bar[1]}。这不应打印大写字母"A":''x41
$string = <<<'EOT'
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should not print a capital 'A': 'x41
EOT;
echo nl2br( $string );
当然,您可能还有其他一些问题,例如 HEREDOC 不扩展十六进制,对象表示法需要括号(也许......