Run PHP CLI from Windows Powershell ISE


Run PHP CLI from Windows Powershell ISE

此问题是关于Windows PowerShell ISE中的美元符号"$"$

我有PHP CLI,希望从Windows PowerShell ISE中的提示符运行一行命令脚本。

php -r "$foo = 'foo';"

只是返回Parse error: parse error in Command line code on line 1,我已经将其缩小到讨厌的美元符号,这在PowerShell中很重要。我能逃脱吗?

我也试过

php -r '$foo = "foo";'

并获得

Notice: Use of undefined constant foo - assumed 'foo' in Command line code on line 1

是的,在美元符号前添加一个反勾:

php -r "`$foo = 'foo';"

这就是您所需要的:

"`$foo = 'foo';"