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

0 php perl

我使用escapeshellarg从php传递到perl

system("perl -e '" . escapeshellarg($inp) . "' >> /tmp/out");
Run Code Online (Sandbox Code Playgroud)

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

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

mar*_*rio 5

请注意,escapeshellarg添加外部单引号本身.

所以应该把它们留下来:

system("perl -e " . escapeshellarg($inp) . " >> /tmp/out");
#              ^                            ^ no extra ' quotes here
Run Code Online (Sandbox Code Playgroud)