Opening Standard Output as a File Handle in PHP
How To Open Standard Output as a File Handle in PHP?
If you want to open the standard output as a file handle yourself, you can use the fopen("php://stdout") function. It creates a special file handle linking to the standard output, and returns the file handle. Once the standard output is opened to a file handle, you can use fwrite() to write data to the starndard output like a regular file. Here is a PHP script example on how to write to standard output:
<?php $stdout = fopen("php://stdout", "w"); fwrite($stdout,"To do:\n"); fwrite($stdout,"Looking for PHP hosting provider!\n"); fclose($stdout); ?>
This script will print:
What's your name? To do: Looking for PHP hosting provider!
If you don't want to open the standard output as a file handle yourself, you can use the constant STDOUT predefined by PHP as the file handle for standard output.
If you are using your script in a Web page, standard output is merged into the Web page HTML document.
print() and echo() also writes to standard output.
2016-11-24, 299👍, 0💬
Can You Copy an Array in PHP? You can create a new array by copying an existing array using the assi...
How To Write a String to a File with a File Handle in PHP? If you have a file handle linked to a fil...
Can You Add Values to an Array without Keys in PHP? Can You Add Values to an Array with a Key? The a...
How To Create a Table To Store Files in PHP? If you using MySQL database and want to store files in ...
How To Read Data from Keyboard (Standard Input) in PHP? If you want to read data from the standard i...