PHP popen() Function
In this chapter you will learn:
- Definition for PHP popen() Function
- Syntax for PHP popen() Function
- Parameter for PHP popen() Function
- Return for PHP popen() Function
- Example - Opens a pipe to the program specified in the command parameter
Definition
The popen() function opens a pipe to the program specified in the command parameter.
Syntax
PHP popen() Function has the following syntax.
popen(command,mode)
Parameter
Parameter | Is Required | Description |
---|---|---|
command | Required. | Command to execute |
mode | Required. | Connection mode. |
Possible values for the mode:
- r: Read only
- w: Write only (opens and clears existing file or creates a new file)
Return
This function returns FALSE if an error occurs.
Example
Opens a pipe to the program specified in the command parameter
<?php// j a va 2 s .c o m
$file = popen("/bin/ls","r");
//some code to be executed
pclose($file);
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP readdir() Function
- Syntax for PHP readdir() Function
- Parameter for PHP readdir() Function
- Return for PHP readdir() Function
- Example - returns the name of the next entry in a directory
- Example - Open a directory, read its contents, then close
Home » PHP Tutorial » PHP File Functions