The fgets function returns a string it reads from a file specified by the file handle, which
must have been created with fopen, fsockopen, or popen. It will attempt to read as many
characters as specified by the length argument less one. A linebreak character is treated
as a stopping point as is the end of the file. It will be included in the returned string.
Some other functions for reading from a file are: fgetc, fgetcsv, fgetss, fread,
gzgets.
<?
// open file and print each line
if($myFile = fopen("data.txt", "r"))
{
while(!feof($myFile))
{
$myLine = fgets($myFile, 255);
print($myLine);
}
fclose($myFile);
}
?>
string fgetss(integer file_handle, integer length, string ignore)
The fgetss function is in all respects identical to fgets except that it attempts to strip
any HTML or PHP code before returning a string. The optional ignore argument
specifies tags that are allowed to pass through unchanged. Note that if you wish to ignore
a tag, you need only specify theopening form. Some other functions for reading from a
file are: fgetc, fgetcsv, fgetss, fread, gzgets. If you wish to preserve HTML
butprevent it from being interpreted, you can use the htmlentities function.
<?
// open file and print each line,
//stripping HTML except for anchor tags
if($myFile = fopen("index.html", "r"))
{
while(!feof($myFile))
{
$myLine = fgetss($myFile, 1024, ");
print($myLine);
}
fclose($myFile);
}
?>
array file(string filename)