A method to read data from a file using php functions.
<?php
//read from file
function readFromFile($filename)
{
if (!file_exists($filename))
{
echo "file not found";
echo "<br/>";
}
else
{
$fh = fopen($filename,"r") or die("Can't open file");
while(!feof($fh))
{
$line = fgets($fh);
echo "$line<br/>";
}
fclose($fh);
echo "<br/>";
echo "File read successfully.";
}
return;
}
echo "<br/>";
readFromFile("test.txt");
echo "<br/>";
?>
<?php
//read from file
function readFromFile($filename)
{
if (!file_exists($filename))
{
echo "file not found";
echo "<br/>";
}
else
{
$fh = fopen($filename,"r") or die("Can't open file");
while(!feof($fh))
{
$line = fgets($fh);
echo "$line<br/>";
}
fclose($fh);
echo "<br/>";
echo "File read successfully.";
}
return;
}
echo "<br/>";
readFromFile("test.txt");
echo "<br/>";
?>
No comments:
Post a Comment