【发布时间】:2019-11-27 05:40:32
【问题描述】:
从this answer to a previous question 我看到,要从命令行(不是从 PowerShell,如果人们这么想的话)在双引号字符串中只得到一个双引号,就必须连续使用三个双引号。所以,直到最近,我一直使用三个双引号没有问题。
C:\>php -r "echo '"""' . trim(trim(trim(trim(trim(42))))) . '"""';"
)))) was unexpected at this time.
C:\>php -r "echo '"""' . trim(trim(trim(trim(42)))) . '"""';"
))) was unexpected at this time.
C:\>php -r "echo '"""' . trim(trim(trim(42))) . '"""';"
)) was unexpected at this time.
C:\>php -r "echo '"""' . trim(trim(42)) . '"""';"
) was unexpected at this time.
C:\>php -r "echo '"""' . trim(42) . '"""';"
. was unexpected at this time.
C:\>php -r "echo '"""' . '"""';"
""
为什么三个双引号在上面的例子中除了最后一个之外不起作用?
【问题讨论】:
-
你需要这样:-
"echo '" . trim(trim(trim(trim(trim(42))))) ."';"; -
php -r "echo '"""' . trim(42) . '"""';";在行尾添加另一个分号,这对我有用 -
@YashKaranke 这给了我同样的错误。
-
为什么不以正确的方式转义双引号 (
php -r "echo '\"' . trim(42) . '\"';" //output: "42")?这使得代码顺便说一句。可读性也更好! -
@YashKaranke Web 服务器无关紧要,因为它是 CLI,而不是 CGI。我使用的是 PHP 7.3.9,奇怪的是,PHP 7.1-7.3 版本的行为相同,但 PHP 7.0 不同!
标签: php windows console-application