This article mainly introduces PHP to read the contents of the three ways, the need for friends can refer to the following
PHP three ways to read the contents of a file: //************** The first way to read ***************************** code is as follows: Header ("Content-type : Text/html;charset=utf-8 "); //file path $file _path=" text.txt "; //judge whether there is this file if (file_exists ($file _path) { if ($fp =fopen ($file _path, "A +")) { //Read file $conn =fread ($fp, FileSize ($file _path)); // Replace string $conn =str_replace ("RN", "<br/>", $conn); echo $conn. " <br/> "; }else{ echo" file cannot be opened "; } }else{ echo" does not have this file; } fclose ($FP); //******************* The second way to read *************************** code is as follows: Header ("content-type:text/ Html;charset=utf-8 "); //file path $file _path=" Text.txt "; $conn =file_get_contents ($file _path); $ Conn=str_replace ("RN", "<br/>", file_get_contents ($file _path)); echo $conn; fclose ($fp); //****************** The third way to read, loop read ***************** code as follows: Header ("Content-type:text/html;charset =utf-8 "); File path $file _path= "text.txt"; //Determine if file exists if (file_exists ($file _path)) { //Determine if file can open if ( $FP =fopen ($file _path, "A +")) { $buffer =1024; //edge reading to determine whether the end of the file is at $STR = ""; while (!feof ($fp)) { $STR. =fread ($fp, $buffer); } }else{ echo "file cannot open"; } }else{ echo "does not have this file"; nbsp } //Replacement characters $STR =str_replace ("RN", "<br>", $str); echo $str; fclose ($fp); Functions that read the INI configuration file: $arr =parse_ini_file ("Config.ini"); //Returns the array echo $arr [' Host ']. " <br/> "; echo $arr [' username ']." <br/> "; echo $arr [' Password ']." <br/> ";