Thursday 12 February 2009

Php Stream

The first thing you learn about in PHP is probably how to print something. This is usually done with a call to the echo or print, but there is another way to print things by writing content directly to the output buffer. The following code looks like you are writing to a file, but the text will appear in the browser window because we are writing to the php://output output stream.

$fp = fopen("php://output", 'r+');
fputs($fp, "Hello World");

Or another way…

file_put_contents("php://output", "Hello World");

The php://output stream is an encapsulation between PHP and the browser. The stream doesn’t really exist, but PHP knows what to do with it.

More about Php stream:
http://uk3.php.net/manual/en/function.stream-get-contents.php

1 comment:

Trand said...

Ye, it is very important to work with php form further

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter