Function name: shell_exec()
Applicable version: PHP 4, PHP 5, PHP 7
Function description: The shell_exec() function executes the specified shell command and returns the output of the command as a string. Unlike the exec() function, the shell_exec() function returns the complete result of the command output, not just the last line.
Syntax: shell_exec ( string $cmd ) : string|NULL
parameter:
Return value:
Example 1:
$output = shell_exec('ls -l'); echo "<pre>$output</pre>";
The above example executes the "ls -l" command and assigns the result to the $output variable. Then, use the <pre>
tag to output the result as is to the browser.
Example 2:
$output = shell_exec('php -v'); echo "<pre>$output</pre>";
The above example will execute the "php -v" command, display the PHP version information, and assign the result to the $output variable. Then, use the <pre>
tag to output the result as is to the browser.
Notes: