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

yipeiwu_com6年前PHP代码库
<?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 file_exists问题杂谈

PHP file_exists问题杂谈

问题   公司有个框架是基于smarty写的,我负责php的升级,维护人员把新环境布上来之后,测试人员找我提出经常报错(错误:提示找不到文件的)。   我追踪了一下代码,原来是smart...

php cookie的操作实现代码(登录)

第一个文件login_frm.php这个是登录窗口 代码 复制代码 代码如下: <html> <head> <meta http-equiv="Conten...

解析php addslashes()与addclashes()函数的区别和比较

PHP addcslashes() 函数定义和用法addcslashes() 函数在指定的字符前添加反斜杠。语法addcslashes(string,characters)参数 描述 s...

php下的权限算法的实现

权限设计 大概有这几种模式: 用户+组+角色+权限 用户+组+权限 用户+角色+权限 用户+权限 最近看了别人的设计方法,大多以“整数”来表示权限值,如添加、浏览、删除和修改,分别用1...

php中explode函数用法分析

本文实例分析了php中explode函数用法。分享给大家供大家参考。具体如下: explode(string separator,string string [,int limit])...