PHP Three ways to read the contents of a file:
First read mode *****************************
Header ("Content-type:text/html;charset=utf-8");//file path $file_path= "Text.txt";//Determine if 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 ("\ r \ n "," <br/> ", $conn); Echo $conn." <br/> ";} Else{echo "File not open";}} Else{echo "no this file";} Fclose ($FP);
Second Read mode **********************************
Header ("Content-type:text/html;charset=utf-8");//file path $file_path= "Text.txt"; $conn =file_get_contents ($file _path) ; $conn =str_replace ("\ r \ n", "<br/>", file_get_contents ($file _path)); Echo $conn; fclose ($FP);
Third read mode, loop read ******************************
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 open if ($fp =fopen ($file _path, "A +") {$buffer =1024;//side read to determine if the end of the file $str= ""; while (!feof ( $FP) {$str. =fread ($fp, $buffer);}} Else{echo "file cannot be opened";}} Else{echo "no this file";} Replace character $str=str_replace ("\ r \ n", "<br>", $str), Echo $str, fclose ($fp), function to read the INI configuration file: $arr =parse_ini_file (" Config.ini ");//Returns an array of echo $arr [' Host ']. <br/> "; Echo $arr [' username ']." <br/> "; Echo $arr [' Password ']." <br/> ";