Answers for "fgets php"

PHP
3

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.
}
Posted by: Guest on May-22-2020
1

read line by line php

<?php
	
	$file = new SplFileObject("file.txt");

	while(!$file->eof())
	  {
		echo $file->fgets()."<br/>";
	  }

	$file = null;

?>
Posted by: Guest on December-25-2020
-1

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
Posted by: Guest on October-12-2021

Browse Popular Code Answers by Language