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");?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号