Home >Backend Development >PHP Tutorial >Node reads files PHP reads file content code txt, js, etc.
/*
Author: bjf;
Application: Read file content;
*/
function read_file_content($FileName)
{
//open file
$fp=fopen($FileName,"r") ;
$data="";
while(!feof($fp))
{
//read the file
$data.=fread($fp,4096);
}
//close the file
fclose( $fp);
//delete the file
//unlink($FileName);
//return the content from the file
echo $data;
}
read_file_content("a.html")
?>
fread The difference with fgets
fread: Calculate the length in bytes, read data according to the specified length and number of times, and stop after encountering the end or completing the specified length of reading.
fgets: Read the entire line, and encounter a carriage return or line feed. Stop at the end. Used in text mode.
The above introduces Node to read files, PHP to read file content code txt, js, etc., including the content of Node to read files. I hope it will be helpful to friends who are interested in PHP tutorials.