2
我打电话从命令行PHP脚本:如何将shell变量作为参数传递给PHP函数调用?
/usr/bin/php -r "require '/path/to/php/dummy.php'; echo getFunction(\"DummyParameter\")";
通话就像一个魅力,PHP函数返回正确的值。我想用$ShellVariable
替换DummyParameter
。当我替换DummyParameter
时,它应该作为"$ShellVariable"
字符串传递。这里是我曾尝试过的:
/usr/bin/php -r "require '/path/to/php/dummy.php'; echo getFunction(\"$ShellVariable\")";
有什么方法可以将shell变量作为函数参数传递给PHP脚本吗?
在此先感谢。
你也许可以,但得到适当的转义将可能很难得到正确和将需要相当混乱的代码。这是一个概念证明吗?因为如果你只是在一个文件中写代码,这是微不足道的。 –