Page 1 of 1

Can't think of the function. Create a user defined handle

Posted: Tue Aug 15, 2006 6:41 am
by Chris Corbyn
Maybe I'm just imaging it but I seem to remember stubmling across a function/set of functions on php.net which allow you to do something like:

Code: Select all

$handle = this_mystery_function_i_cant_remember();

fwrite($handle, 'something');
echo fgets($handle);
You actually define what happens when you fwrite to the handle and when you fget from it. It doesn't create a file, or a socket AFAIK... it just operates on a variable.

Am I completely imaging this or does this function exist? I can't find it :(

Posted: Tue Aug 15, 2006 6:55 am
by sweatje
I think perhaps your are fseeking the stream functions.

Posted: Tue Aug 15, 2006 8:35 am
by Jenk
one of these?

I would try to hazard a guess, but I'm not even sure I've ever heard of some of those on there..

Posted: Tue Aug 15, 2006 8:38 am
by feyd
It sounds like the stream functions..

Posted: Tue Aug 15, 2006 9:01 am
by Oren
From the manual:

Code: Select all

<?php

	$temp = tmpfile();

	fwrite($temp, "writing to tempfile");
	fseek($temp, 0);

	echo fread($temp, 1024);

	fclose($temp); // this removes the file

?>
The above example will output:

writing to tempfile

Posted: Wed Aug 16, 2006 7:01 pm
by Chris Corbyn
Oren wrote:From the manual:

Code: Select all

<?php

	$temp = tmpfile();

	fwrite($temp, "writing to tempfile");
	fseek($temp, 0);

	echo fread($temp, 1024);

	fclose($temp); // this removes the file

?>
The above example will output:

writing to tempfile
Not that ;)

You guys were right.. It was the stream functions I was after. Thanks indeed! ;)