php read file line by line
$handle = fopen("inputfile.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
// process the line read.
}
fclose($handle);
} else {
// error opening the file.
}
php read file line by line
$handle = fopen("inputfile.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
// process the line read.
}
fclose($handle);
} else {
// error opening the file.
}
read line by line php
<?php
$file = new SplFileObject("file.txt");
while(!$file->eof())
{
echo $file->fgets()."<br/>";
}
$file = null;
?>
fgets in php
$fptr = fopen('myfile.txt','r');
if(!$fptr)
{
die("Could not open file");
}
while($line = fgets($fptr))
{
echo $line; //fgets read line by line, if we don't put code in while loop then it will print only one line of code
}
echo "End of the file reached!"; //it only reads one line at a time
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us