Home  >  Article  >  Backend Development  >  PHP read file content code (txt, js, etc.)_PHP tutorial

PHP read file content code (txt, js, etc.)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:42:251281browse

/*
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 and fgets The difference
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 Line break or end stop. Used in text mode.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320960.htmlTechArticle?php /* Author: bjf; Application: Read file content; */ function read_file_content($FileName) { //open file $fp=fopen($FileName,"r"); $data=""; while(!feof($fp)) { //read the file $da...
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