如何在PHP系统调用中转义引号?

时间:2012-07-04 14:34:25

标签: php perl

我使用escapeshellarg

从php传递给perl
system("perl -e '" . escapeshellarg($inp) . "' >> /tmp/out");

从perl获取未终止的引用字符串。

输入为:'Single quoted terminated string\n';

1 个答案:

答案 0 :(得分:5)

请注意,escapeshellarg会自行添加外部单引号。

所以应该把它们排除在外:

system("perl -e " . escapeshellarg($inp) . " >> /tmp/out");
#              ^                            ^ no extra ' quotes here
相关问题