Hi Reader's,
Welcome to FindNerd, today we are going to discuss what is the use of fgets in PHP ?
If you want a function that returns a line from an open file and after a specific length(the length that is specified by you) it should stop returning on a new line for that you can use fgets() function.
syntax of fgets() :
fgets(file,length)
There are two main parameter of fgets() function
1- file:-this is a required parameter and specifies the file to read
2- length:-this is a optional parameter.
you can see below example
<?php
//here define a file variable and call file.txt page and use fopen()
$file = fopen("file.txt","r");
//here call fgets()
echo fgets($file);
//here call fclose() function
fclose($file);
?>
0 Comment(s)