Three ways to read file content in php (transfer),
Share the three ways to read file content in php.
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)); >
//Replace string
$conn=- str_replace("
", $conn); -
echo $conn."
";
-
}else{
echo - "File cannot be opened";
- }
}else{
- echo
- "No such file";
- }
fclose($fp);
-
-
//*******************Second reading method************************ ********** -
- header(
"content-type:text/html;charset=utf-8"); //File path -
$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="text.txt";
//Determine whether the file exists -
if(file_exists(
$file_path)){
-
//Determine whether the file can be opened
if($fp=
fopen(- $file_path,
-
$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"); -
//returns an array
-
$arr[
'host'].- "
";
echo $arr[ 'username'].- "
";
echo $arr[ 'password'].- "
";
http://www.bkjia.com/PHPjc/1084377.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/1084377.html
TechArticleThree ways to read file content in php (reposted), share the three ways to read file content in php . PHP reads file content: //****************The first reading method************************ ****...