Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

boolean rewind(integer file_handle)


The rewind function moves PHP's internal file pointer back to the beginning of the file.
This is the same as using fseek to move to position zero.


<?
/*
* print a file, then print the first line again
/


// open a local file
$myFile = fopen("data.txt", "r");


while(!feof($myFile))
{
// read a line from the file
$myLine = fgetss($myFile, 255);
print("$myLine
\n");
}
rewind($myFile);
$myLine = fgetss($myFile, 255);
print("$myLine
\n");


// close the file
fclose($myFile);
?>


boolean rewinddir(integer handle)


The rewinddir function resets PHP's internal pointer to the beginning of a directory
listing. It returns TRUE unless an error occurs, in which case it returns FALSE. The handle
is an integer returned by opendir.


<?
/*
* print the current directory in a table
/
print("<TABLE BORDER=\"1\">\n");


// open directory
$myDirectory = opendir(".");


print("\n");
print("Filename\n");


// get each entry
while($entryName = readdir($myDirectory))
{
print("$entryName\n");
}

Free download pdf