【发布时间】:2016-11-29 07:07:30
【问题描述】:
我正在从命令行调用 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脚本?
提前致谢。
【问题讨论】:
-
你可能可以——但是正确的转义可能很难做到,并且需要相当混乱的代码。它是概念证明吗?因为如果你只是将代码写在一个文件中,那是微不足道的。
标签: php shell command-line-interface