Execution Operators in PHP : Tutorial



backticks (``) are used as Execution Operator in PHP.

The contents within the backticks are executed as shell commands returning the output, which can be assigned to a variable.
Note that these (``) are not single-quotes!
Execution Operator is identical to shell_exec() function.
The backtick operator is disabled when safe mode is enabled or shell_exec() is disabled.
Backticks cannot be used within double-quoted strings.
We can even run Windows dos commands.


Example 1:
<?php

$executionOpOutput = `ls -ltr`;
echo "<pre>$executionOpOutput</pre>";

}

?>
Output

Example 2: Running DOS commands
<?php

$executionOpOutput = `ver`;
echo "<pre>$executionOpOutput</pre>";

}

?>
Output

Microsoft Windows [Version 6.3.9600]
Example 3: Running DOS dir commands
<?php

$executionOpOutput = `ver`;
echo "<pre>$executionOpOutput</pre>";

}

?>
Output

Volume in drive I is Code2care Volume Serial Number is 70BE-20EE Directory of I:\xampp\htdocs\xampp\Tutorials 12/26/2013 08:38 PM