1. File Reading
<? Php // read the file $ file_path = "text.txt"; if (! File_exists ($ file_path) {echo "file does not exist"; exit () ;}// open the file $ fp = fopen ($ file_path, "a + "); // read the file $ content = fread ($ fp, filesize ($ file_path); echo "the file content is: <br/> "; // by default, after the content is output to the webpage, It is not displayed with line breaks, because the web page does not recognize \ r \ n // All \ r \ n => <br/> $ content = str_replace ("\ r \ n ", "<br/>", $ content); echo $ content; fclose ($ fp);?>
2. method 2 for reading files
<? Php // second method of reading files $ file_path = "text.txt"; if (! File_exists ($ file_path) {echo "file does not exist"; exit () ;}$ content = file_get_contents ($ file_path); $ content = str_replace ("\ r \ n ", "<br/>", $ content); echo $ content;?>
3. The third method is to read data cyclically (to deal with large files)
<? Php // The third method for reading data. It reads data cyclically (against large files) $ file_path = "text.txt"; if (! File_exists ($ file_path) {echo "file does not exist"; exit () ;}// open the file $ fp = fopen ($ file_path, "a + "); // defines the number of bytes read each time. $ buffer = 1024; // one side is read. While determining whether it reaches the end of the file while (! Feof ($ fp) {// read data by 1024 bytes $ content = fread ($ fp, $ buffer); echo $ content;} fclose ($ fp);?>
4. File Reading application: When we connect to the database, we can configure the specified data to a file, and then obtain information in real time when PHP is running.
Db. ini file
host=127.0.0.1user=rootpwd=rootdb=test
Get File
<? Php $ arr = parse_ini_file ("db. ini "); echo" <pre> "; print_r ($ arr); echo" </pre> "; echo $ arr ['host']; // connect to the database $ conn = mysql_connect ($ arr ['host'], $ arr ['user'], $ arr ['pwd']); if (! $ Conn) {echo "error";} echo "OK";?>