PEAR Manual
This manual is provided as a courtesy. It is not an official source. Please check pear.php.net for updated information.
The following example shows you how to register Stream_Var as a wrapper for the stream functions.
Example 53-1. Registering Stream_Var
require_once "Stream/Var.php"; stream_wrapper_register( "var", "Stream_Var" );
The following example show you how to access scalar variables with fopen(), fread(), frwite() and fclose().
Example 53-2. Accessing scalar variables
require_once "Stream/Var.php"; stream_wrapper_register( "var", "Stream_Var" ); $foo = "I really like tomatoes."; echo "Content of foo: $foo<br />"; $fp = fopen('var://GLOBALS/foo','r+'); $data = fread($fp, 9); echo "Read from stream: $data<br />"; fwrite($fp,"hate"); fclose($fp); echo "Content of foo: $foo<br />";
The following example shows how to use opendir() to access an array.
Example 53-3. Accessing an array
require_once "Stream/Var.php"; stream_wrapper_register( "var", "Stream_Var" ); $dirname = 'var://_SERVER'; $dir = opendir($dirname); echo "<strong>opening directory '$dirname'</strong><br><br>"; while ($entry = readdir($dir)) { echo "opening file $dirname/$entry<br />"; if (!$fp = @fopen($dirname."/".$entry,"r")) { echo "seems to be a directory<br /><br />"; continue; } echo "reading from $entry<br />"; while (!feof($fp)) { echo fread($fp, 16); } fclose($fp); echo "<br /><br />"; } closedir($dir);
If you want to take a look at some more examples, just install the package and they will be installed in the docs directory.