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学习中常见的各类问题,约有两千多行代码,都是非常实用的技巧。分享给大家供大家参考。具体如下: //语法错误(syntax error)在语法分析阶段,源代码并未被执行...

php自定义类fsocket模拟post或get请求的方法

本文实例讲述了php自定义类fsocket模拟post或get请求的方法。分享给大家供大家参考。具体如下: zsocket.class.php文件如下: <?php c...

php计算数组不为空元素个数的方法

复制代码 代码如下: <?php $arr = array( 1=>"11", 2=>"22", 3=>"33", 4=>"" ); print_r(cou...

smarty静态实验表明,网络上是错的~呵呵

复制代码 代码如下:<?   require_once("Smarty/libs/Smarty.class.php");   $smarty...

PHP中include与require使用方法区别详解

在PHP变成中,include()与require()的功能相同,include(include_once) 与 require(require_once)都是把把包含的文件代码读入到指...