<?php//The first way to read the file $file _path = "Db.ini";
Determine if the file exists (must be judged) if (file_exists ($file _path)) {//Open file, specify file path, read mode $fp = fopen ($file _path, "A +");
Read length $con = fread ($fp, FileSize ($file _path));
The replacement character//php does not deal with special characters and needs to be converted $con = Str_replace ("\ n", "<br/>", $con);
Echo $con;
}else{echo "file does not exist";
//close file, must fclose ($FP);
The second way to read the file, automatically closes the file//direct access to the file content//To determine whether the file exists (must be judged) if (file_exists ($file _path)) {//directly get the contents of the file
$con = file_get_contents ($file _path);
Substitution character $con = str_replace ("\ n", "<br/>", $con);
Echo $con;
}else{echo "file does not exist";
//I will close the file///Third way to read the file//while Circular read, suitable for large files//To determine whether the file exists (must be judged) if (file_exists ($file _path)) {
Open File $fp = fopen ($file _path, "A +");
$str = "";
$buffer = 1024;
While loop read, suitable for large file while (!feof ($fp)) { $str = Fread ($fp, $buffer);
$str = Str_replace ("\ n", "<br/>", $str);
Echo $str;
//close file, must fclose ($FP);
}else{echo "file does not exist";
The//fourth read file (automatically closes file) if (file_exists ($file _path)) {$arr = Parse_ini_file ("Db.ini");
Print_r ($arr);
mysql_connect ($arr [' Host '], $arr [' User '], $arr [' Password ']);
}else{echo "file does not exist";
}?> </body>