system()

system() — Execute an external program and display the output.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

system() is just like the C version of the function in that it executes the given command and outputs the result.

Signature

system(string $command, int &$result_code = null): string|false

Parameters

ParameterTypeWhat it takes
$commandstringThe command that will be executed.
&$result_codeintIf the result_code argument is present, then the return status of the executed command will be written to this variable.

Return value

Returns the last line of the command output on success, and false on failure.

Example

A runnable snippet:

echo '<pre>'; // Outputs all the result of shellcommand "ls", and returns // the last output line into $last_line. Stores the return value // of the shell command in $retval. $last_line = system('ls', $retval); // Printing additional info echo ' </pre> <hr />Last line of the output: ' . $last_line . ' <hr />Return value: ' . $retval;

See also

exec(), passthru(), popen(), escapeshellcmd()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page system() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.