PHP three ways to read the contents of a file://************** the first way to read the ***************************** code is as follows: Header ("Content-type:text/html;charset =utf-8 ");//Tell PHP preprocessor to pass content UTF8 format to browserFile path $file _path= "Text.txt"; //determine if there is a 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" without this document "; } fclose ($FP); //******************* the second reading method *************************** 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 reading method, the loop reads the ***************** code as follows: Header ("Content-type:text/html;charset =utf-8 "); //file path $file _path=" Text.txt "; //determine if the file exists if (file_exists ($file _path)) { // Determine if the file can be opened if ($fp =fopen ($file _path, "A +") { $buffer =1024; //side read to determine whether the end of the file &nBSP; $str = ""; while (!feof ($fp)) { $str. =fread ($fp, $buffer); } }else{ echo "file cannot be opened"; } }else{ echo "no this file"; } //replacement character $str =str_replace ("RN", "<br>", $str); echo $str; fclose ($fp); the function: $arr =parse_ini_file ("Config.ini") that reads the INI configuration file; //returns an array echo $arr [' Host ']. <br/> "; echo $arr [' username ']." <br/> "; echo $arr [' Password ']." <br/> ";
PHP-Read text file contents