PHP reads file content:
-
- header("content-type:text/html;charset=utf-8");
-
- $file_path="text.txt";
-
- if(file_exists($file_path)){
- if($fp=fopen($file_path,"a+")){
-
- $conn=fread($fp, filesize($file_path));
-
- $conn=str_replace("rn","
",$conn);
- echo $conn."
";
- }else{
- echo "The file cannot be opened";
- }
- }else{
- echo "No such file";
- }
- fclose($fp);
-
-
-
- header("content-type:text/html;charset=utf-8");
-
- $file_path="text.txt";
-
$conn=file_get_contents($file_path); >
-
$conn=str_replace("rn","
",file_get_contents($file_path));
-
echo $conn;
- fclose($fp);
-
-
-
//******************The third reading method, loop reading****************** ******
- 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 be opened
-
if($fp=fopen($file_path,"a+")){
-
$buffer=1024;
-
//Judge whether you have reached the end of the file while reading
-
$str="";
-
while(!feof($fp)){
-
$str.=fread($fp,$buffer);
- }
- }else{
-
echo "File cannot be opened";
- }
- }else{
-
echo "No such file";
- }
-
- $str=str_replace("rn","
",$str);
- echo $str;
- fclose($fp);
- Function to read INI configuration file:
- $arr=parse_ini_file("config.ini") ;
-
- echo $arr['host']."
";
- echo $arr['username']."
";
- echo $arr['password']."
";
Reference link:
Code for php to read file content into string and process it
Learn how to read file content in php
http://www.bkjia.com/PHPjc/729832.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/729832.htmlTechArticlephp reads file content: //**************First A reading method**************************** header( "content-type:text/html;charset=utf-8" ); //File path $file_path = "text.txt" ;...