In short
- escapeshellarg: used to enclose an argument with single quotes, and it escapes quotes in the argument.
- escapeshellcmd: used to exit shell metacharacters ie <,>, | etc.
Assuming your php version relies on bash to execute the command, we know from bash manual ,
. , .
, :
$c = escapeshellcmd( $cmd ) . ' ' . escapeshellarg( $arg1 );
, $c : exec, system, passthru .. , . :
$cmd = 'echo';
$arg = 'TEST\0ING';
$c = escapeshellcmd( $cmd ) . ' ' . escapeshellarg( $arg1 );
exec( $c . ' > output.txt');
exec '\ 0' , output.txt '\ 0'. Ubuntu PHP 5.4.6. , , . , escapeshellcmd , '\', :
$c = escapeshellcmd( $cmd . ' ' . escapeshellarg( $arg1 ) );
exec( $c . ' > output.txt'); // writes TEST\0ING to output.txt
, ($ cmd), .
, escapeshellcmd . ' > output.txt' , ' > ' .
:
. . , , .
, , -.
, escapeshellcmd .