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 循环删除无限分类子节点的实现代码

复制代码 代码如下:<?php    private  function _deleteSubNode($ids){   ...

PHP编程文件处理类SplFileObject和SplFileInfo用法实例分析

本文实例讲述了PHP编程文件处理类SplFileObject和SplFileInfo用法。分享给大家供大家参考,具体如下: php对于大文件的处理除了用以下方法外还可以直接调用linux...

PHP Warning: Module 'modulename' already loaded in问题解决办法

出现标题这样的错误大概是: 1、模块加载了两次,所以php -i|grep Configure,看一下配置文件和配置include的目录,对于这些文件中是否有同名的module 2、动态...

PHP删除数组中的特定元素的代码

比如下面的程序: 复制代码 代码如下: <?php $arr = array('apple','banana','cat','dog'); unset($arr[2]); prin...

Windows下XDebug 手工配置与使用说明

1. 下载XDebug二进制文件: http://www.xdebug.org/download.php   5.2 http://www.xdebug.org/files/php_xd...