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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

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

Post 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 :(
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post by sweatje »

I think perhaps your are fseeking the stream functions.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It sounds like the stream functions..
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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! ;)
Post Reply