Php can read file content in three ways. This article mainly introduces three methods for php to read file content. you can refer to the following three methods for php to read file content: * This article describes three methods for php to read files. method, for more information, see
Three methods for php to read file content: // ************** first method of reading ******************** the *** code is as follows: header ("content-type: text/html; charset = utf-8"); // file path $ file_path = "text.txt "; // determine whether this file exists 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 ","
", $ Conn); echo $ conn ."
";}Else {echo" file cannot be opened ";}} else {echo" This file is not available ";}fclose ($ fp ); // ******************* second read method *************** the *** 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 ("\ r \ n ","
", File_get_contents ($ file_path); echo $ conn; fclose ($ fp ); // ******************** the third read method, the code for cyclically reading **************** is as follows: header ("content-type: text/html; charset = utf-8 "); // file path $ file_path = "text.txt"; // Determine whether the file exists if (file_exists ($ file_path )) {// Determine whether the file can open if ($ fp = fopen ($ file_path, "a +") {$ buffer = 1024; // read and judge whether the file ends at $ str = ""; while (! Feof ($ fp) {$ str. = fread ($ fp, $ buffer) ;}} the else {echo "file cannot be opened" ;}} else {echo "This file is not available ";} // replace the character $ str = str_replace ("\ r \ n ","
", $ Str); echo $ str; fclose ($ fp); function used to read the INI configuration file: $ arr = parse_ini_file (" config. ini "); // The Returned array echo $ arr ['host']."
"; Echo $ arr ['username']."
"; Echo $ arr ['password']."
";
Javasphp can read the file content in three ways: // ************** first method of reading ***********...