Three ways for PHP to read the contents of a file:
The first way of reading *****************************
Copy Code code as follows:
Header ("Content-type:text/html;charset=utf-8");
File path
$file _path= "Text.txt";
To determine if there is this file
if (file_exists ($file _path)) {
if ($fp =fopen ($file _path, "A +")) {
Reading files
$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 "does not have this document";
}
Fclose ($FP);
The second way of reading ***************************
Copy Code code 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 ("\ r \ n", "<br/>", file_get_contents ($file _path));
echo $conn;
Fclose ($FP);
The third way of reading, cyclic reading *****************
Copy Code code as follows:
Header ("Content-type:text/html;charset=utf-8");
//file path
$file _path= "Text.txt";
//To determine if the file exists
if (file_exists ($file _path)) {
///To determine if the file can be opened
if ($fp =fopen ($file _path, "A +")) {
$buffer =10 24;
//Edge read to determine whether the end of the file
$str = "";
while (!feof ($fp)) {
$str. =fread ($fp, $buffer);
}
}else{
echo "file cannot be opened";
}
}else{
echo "does not have this file";
}
//replacement character
$str =str_replace ("\ r \ n", "<br>", $str);
Echo $str;
Fclose ($FP);
functions to 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/> ";