note 16844 added to function.fopen
| From: | cb at fuf dot de | Date: | Thu, 15 Nov 2001 17:03:34 +0000 |
| Subject: | note 16844 added to function.fopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-20879@lists.php.net to get a copy of this message | ||
i allways thought variables (also a filepointer is just a variable) needs
to be global to access them in a function.
but:
function foo($filepointer)
{
while ($oneline != 'end')
{
$oneline=fgets($filepointer, '1024');
print $oneline;
}
}
$filepointer=fopen("onefile.txt", "r");
$oneline="";
while (!feof($filepointer))
{
$oneline=fgets($filepointer, "1024");
if ($oneline == "begin")
{
foo($filepointer);
} print $oneline;
}
onefile.txt:
row1
row2
begin
row4
row5
ende
row7
row8
prints all lines 1 time!!
i thought that the filepointer when
calling the function is at line 3
than, in the function, the filepointer
will go to line 6
but after the function the filepointer
in the global script got to be at
line 3 again but he is at line 6 too!!!
there is no global in the function,
no "&" in function-call
any answers because i don't understand
--
http://www.php.net/manual/en/function.fopen.php
http://master.php.net/manage/user-notes.php?action=edit+16844
http://master.php.net/manage/user-notes.php?action=delete+16844
http://master.php.net/manage/user-notes.php?action=reject+16844