Programster's Blog

Tutorials focusing on Linux, programming, and open-source

PHP Cheatsheet

PHP

As with all cheatsheets, this is a work in progress and I'll keep adding to it.

Related Posts

Get File Handle For Output Stream

There are many useful functions in the standard library that expect a file handle to write to, but you want to output the the output stream instead. An easy solution for this is to get a handle on the output stream like so:

$fileHandle = fopen("php://output", 'w');

Then you can do something like:

$fileHandle = fopen("php://output", 'w');
$myArray = ["hello", "world"];
fputcsv($fileHandle, $myArray);

Feel free to read more on streams in case you want to do anything funky with the input stream etc.