1, the Read file function has
(1) fread (file name, read size), such as Fread ($file _path,filesize ($file _path));
(2) file_get_contents (file name, this function actually contains fopen (file) +fread (file) +fclose (file));
, 2, there are three ways to read files
The first way to read files:
/* The first way to read the file */$file _path = "Test.txt", if (file_exists ($file _path)) { //Open file $fp = fopen ($file _path, "A +"); Read the content and enter $conn = fread ($fp, FileSize ($file _path)); echo "The contents of the file is:<br/>"; The newline character in the Web page is <br/> the line break in the text is \ r \ n, you need to replace the newline character $conn = Str_replace ("\ r \ n", "<br/>", $conn); echo $conn; Fclose ($file _path);} else{ echo ' file does not exist! ‘;}
The second way of reading files:
/* The second way to read the file */$file _path = "Test.txt"; $conn = file_get_contents ($file _path); $conn = Str_replace ("\ r \ n", "<br/>", $conn); Echo $conn;
The third way to read files:
/* There is a flaw in the first two ways, if the read file is too large, it is prone to error, so the third Way is recommended *//* the third method of reading the file */$file _path = "Test.txt"; if (file_exists ($file _path)) { $fp = fopen ($file _path, "A +"); $buffer = 1024x768; $str = ""; while (!feof ($FB)) { $str. = Fread ($fp, $buffer); } $str = Str_replace ("\ r \ n", "<br/>", $str); echo $str; Fclose ($file _path);} else{ echo "file does not exist! ";}
Three, read the file