Home > Backend Development > PHP Tutorial > felayman-php_读取文件内容的三种步骤

felayman-php_读取文件内容的三种步骤

WBOY
Release: 2016-06-13 11:54:01
Original
821 people have browsed it

felayman-----php_读取文件内容的三种方法

<?php /** * Created by PhpStorm. * User: FelayMan * Date: 14-4-7 * Time: 下午6:14 */    header("content-type:text/html;charset=utf-8");    //第一种方式获取文件内容   function getallcontent1($filename){       //file — 把整个文件读入一个数组中       $content = file_get_contents($filename);       return $content;   }    //第二种方式获取文件内容    function getallcontent2($filename){        $arr = file($filename);        $content='';        foreach($arr as $value){            $content.=$value;        }        $content.=iconv("gbk","utf-8",$content);        return $content;    }    //第三种方式获取文件内容    function getallcontent3($filename){        readfile($filename);    }   //$content =  getallcontent1("index.txt");   //$content =  getallcontent2("index.txt");   // echo $content;    getallcontent3("index.txt");?>
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template