1、读取文件
 
<?php
    //读取文件
    $file_path="text.txt";
    if(!file_exists($file_path)){
        echo "文件不存在";
        exit();
    }
    
    //打开文件
    $fp=fopen($file_path,"a+");
    //读取文件
    $content=fread($fp,filesize($file_path));
    echo "文件内容是:<br/>";
    //默认情况下把内容输出到网页后,不会换行显示,因为网页不识别rn
    //所有要把rn =><br/>
    
    $content=str_replace("rn","<br/>",$content);
    echo  $content;
    fclose($fp);
?>
2、读取文件的第二种方式
 
<?php
   //第二种读取文件的方式
    $file_path="text.txt";
    if(!file_exists($file_path)){
        echo "文件不存在";
        exit();
    }
    $content=file_get_contents($file_path);
    $content=str_replace("rn","<br/>",$content);
    echo  $content;
?>
3、循环读取(对付大文件)的方式
 
<?php
    //第三种读取方法,循环读取(对付大文件)
    $file_path="text.txt";
    if(!file_exists($file_path)){
        echo "文件不存在";
        exit();
    }
    //打开文件
    $fp=fopen($file_path,"a+");
    //定义每次读取的多少字节
    $buffer=1024;
    //一边读取。一边判断是否达到文件末尾
    while(!feof($fp)){
        //按1024个字节读取数据
        $content=fread($fp,$buffer);
        echo $content;
    }
    fclose($fp);
?>
4、读取ini配置文件
1)、db.ini 文件
 
2)、读取文件的代码