sed 不适用于 PHP exec 函数 [英] sed doesn't work with PHP exec function
本文介绍了sed 不适用于 PHP exec 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
echo "sed -i 's/NULL/\\N/g' ".$_REQUEST['para'].".sql";
上述语句有效.但是当我像这样在 exec 中使用它时它失败了......
The above statement works. But it fail when I use it in exec like this...
exec("sed -i 's/NULL//\/\/\N/g' ".$_REQUEST['para'].".sql");
推荐答案
你应该用反斜杠来转义反斜杠,而不是用正斜杠,就像这样:
You should escape backslashes with backslashes, not with forward slashes, like this:
exec("sed -i 's/NULL/\\\\N/g' ".$_REQUEST['para'].".sql");
EDIT 我在没有查看代码实际作用的情况下写了答案.不要这样做,因为 $_REQUEST['para']
可以是用户想要的任何东西,可用于 代码注入.按照其他答案的建议使用 PHP 函数.
EDIT I wrote the answer without looking at what the code actually does. Don't do this, because $_REQUEST['para']
can be whatever the user wants, which can be used for code injection. Use the PHP functions as the other answer suggests.
这篇关于sed 不适用于 PHP exec 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文