Home  >  Article  >  Backend Development  >  Node reads files PHP reads file content code txt, js, etc.

Node reads files PHP reads file content code txt, js, etc.

WBOY
WBOYOriginal
2016-07-29 08:41:221034browse

/*
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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn