PHP 读取文件内容代码(txt,js等)
更新时间:2009年12月06日 00:20:58 作者:
PHP 读取文件内容代码(txt,js等)
<?php
/*
作者:bjf;
应用:读取文件内容;
*/
function read_file_content($FileName)
{
//open file
$fp=fopen($FileName,"r");
$data="";
while(!feof($fp))
{
//read the file
$data.=fread($fp,4096);
}
//close the file
fclose($fp);
//delete the file
//unlink($FileName);
//return the content from the file
echo $data;
}
read_file_content("a.html")
?>
fread与fgets的区别
fread :以字节位计算长度,按照指定的长度和次数读取数据,遇到结尾或完成指定长度读取后停止.
fgets :整行读取,遇到回车换行或结尾停止.在文本方式时使用.
/*
作者:bjf;
应用:读取文件内容;
*/
function read_file_content($FileName)
{
//open file
$fp=fopen($FileName,"r");
$data="";
while(!feof($fp))
{
//read the file
$data.=fread($fp,4096);
}
//close the file
fclose($fp);
//delete the file
//unlink($FileName);
//return the content from the file
echo $data;
}
read_file_content("a.html")
?>
fread与fgets的区别
fread :以字节位计算长度,按照指定的长度和次数读取数据,遇到结尾或完成指定长度读取后停止.
fgets :整行读取,遇到回车换行或结尾停止.在文本方式时使用.
相关文章
php class中public,private,protected的区别以及实例分析
本篇文章是对php class中public,private,protected的区别以及实例进行了详细的分析介绍,需要的朋友参考下2013-06-06php基于curl重写file_get_contents函数实例
这篇文章主要介绍了php基于curl重写file_get_contents函数的方法,结合实例形式分析了php使用curl重写file_get_contents函数实现屏蔽错误提示的相关技巧,需要的朋友可以参考下2016-11-11
最新评论