What is the meaning of php://input
& php://output
and when it needs to use?
Please explain with an example.
php://output allows you to write to the output buffer mechanism in the same way as print() and echo(). php://input allows you to read raw POST data. It is a less memory intensive alternative to $HTTP_RAW_POST_DATA and does not need any special php.
To get input from users, you also have to prompt them to enter something. You can use PHP's `readline() function to get this input from the console.
$a = readline(); In this case, as soon as the user hits enter, the entered value is stored in the variable a. Accept multiple space separated inputs: For this, we use another function explode() together with readline(). The first argument of explode() is the delimiter we want to use.
PHP Stream Introduction Streams are the way of generalizing file, network, data compression, and other operations which share a common set of functions and uses. In its simplest definition, a stream is a resource object which exhibits streamable behavior.
These are two of the streams that PHP provides. Streams can be used by functions like fopen, fwrite, stream_get_contents, etc.
php://input
is a read-only stream that allows you to read the request body sent to it (like uploaded files or POST variables).
$request_body = stream_get_contents('php://input');
php://output
is a writable stream that is sent to the server and will be returned to the browser that requested your page.
$fp = fopen('php://output', 'w');
fwrite($fp, 'Hello World!'); //User will see Hello World!
fclose($fp);
Note that if you are in the CLI, php://output will write data to the command line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With