网络编程 
首页 > 网络编程 > 浏览文章

PHP 读取文件内容代码(txt,js等)

(编辑:jimmy 日期: 2024/9/25 浏览:3 次 )
<?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 :整行读取,遇到回车换行或结尾停止.在文本方式时使用.
上一篇:Php 构造函数construct的前下划线是双的_
下一篇:PHP 用数组降低程序的时间复杂度
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap