This example describes the use of command functions outside of PHP. Share to everyone for your reference, specific as follows:
First of all, to review the self, learning and use of PHP has been back and forth for more than a year, research and use of Linux system for almost a years, I actually did not know that the interpretation of PHP language can directly invoke operation command to manipulate the system ...
The first summary of the operation of Linux, commonly used CD, CP, MV, RM and so on do not mention, it is worth summing up the 1th is that ordinary users in the extraction of root permissions need to add sudo before the command, and then in the VI Editor output line number command is: Set Nu.
PHP's built-in function Exec,system can invoke system commands (shell commands), but in order to use the security mode in the two functions php.ini must be shut down, otherwise PHP is not allowed to invoke system commands for security reasons.
Let's take a look at the PHP Manual's explanation of these two functions:
1. EXEC---Execute external program
Syntax: string exec (String command [, array &output [, int &return_var]])
Description
EXEC () executes the command commands given, but it does not output anything, it simply returns the last line from the result of the command, and if you need to execute a command and get all the data from the command, you can use the PassThru () function.
If a parameter array is given, the specified array is filled with each row that the command outputs. Note: If the array has previously contained elements, EXEC () will append it to the array, if you do not want the function to append elements, you can pass this array to exec () Call Unset () before.
2. System---Execute external programs and display output
Syntax: string system (String command [, int &return_var])
Description
System () executes the given command and outputs the result. If a parameter return_var is given, the status code executing the command will be written to this variable.
If PHP is operating as a server module, System () will try to automatically clear the output buffer of the Web server after each row is output. Success is returned to the last line of the command, and false is returned.
If you need to execute a command and get all the data from the command, you can use the PassThru () function.
These two are all used to invoke the system shell command,
Different points:
EXEC can return all the results of execution to the $output function (array), $status is executed state 0 for success 1 for failure
Systerm does not need to provide the $output function, he is directly returning the result, same $return_var is executing the status code 0 for success 1 for failure
exec Example:
The following are the referenced contents:
<?php
$a = exec ("dir", $out, $status);
Print_r ($a);
Print_r ($out);
Print_r ($status);
? >
System Example:
The following are the referenced contents:
<?php
$a = System ("dir", $out);
Print_r ($a);
Print_r ($out);
? >
More interested in PHP related content readers can view the site topics: "PHP Network Programming Skills Summary", "Php Curl Usage Summary", "PHP Socket Usage Summary", "PHP Regular Expression Usage summary", "PHP string (String) Usage Summary", " PHP array Operation techniques Encyclopedia, "PHP Mathematical Calculation Skills Summary", "PHP object-oriented Programming Introductory Course", "PHP Data structure and algorithm tutorial", "PHP Programming algorithm Summary" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.