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

(singke) #1

print("

Local

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


// open a local file
if(!($myFile = fopen("data.txt", "r")))
{
print("file could not be opened");
exit;
}
while(!feof($myFile))
{
// read a line from the file
$myLine = fgetss($myFile, 255);
print("$myLine
\n");
}


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


boolean fpassthru(integer file_handle)


The fpassthru function prints the contents of the file to the browser. Data from the
current file position to the end are sent, so you can read a few lines and output the rest.
The file is closed after being sent. If an error occurs, fpassthru returns false. The
gzpassthru function offers the same functionality for compressed files.


<?
/*
* Get a Web page, change the title tag
/


// open a file using http protocol
if(!($myFile = fopen("http://www.clearink.com/", "r")))
{
print("file could not be opened");
exit;
}


$KeepSearching = TRUE;


while(!feof($myFile) AND $KeepSearching)
{
// read a line from the file
$myLine = fgets($myFile, 1024);


//watch for body tag
if(eregi("<body", $myLine))
{
//no chance to find a title tag
//after a body tag

Free download pdf