开发者

How to escape strings in for use in bash/sh via PHP's shell_exec?

I've been calling more advanced shell commands from PHP recently using shell_exec

As my commands become more complicated, I keep experiencing errors with things not being escape开发者_开发百科d properly. I want to be able to call shell_exec('echo '.$variable) and no matter what I put in $variable it will just echo it. Some things $variable could include are $ ~ ' " \n \r \c `` ( ) { } ; \

What's the best way to escape a shell command before executing it?


Does escapeshellcmd or escapeshellarg not do what you want?

shell_exec('echo '. escapeshellarg($variable));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜