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设计模式之策略模式原理与用法。分享给大家供大家参考,具体如下: 策略模式(Strategy Pattern) 策略模式是对象的行为模式,用意是对一组算法的封装。动态的...

php获取英文姓名首字母的方法

本文实例讲述了php获取英文姓名首字母的方法。分享给大家供大家参考。具体如下: 这段代码可以根据用户输入的英文姓名,分析出姓名的首字母输出,比如"Billy Bob" to "B.B."...

PHP strtotime函数详解

先看手册介绍: strtotime — 将任何英文文本的日期时间描述解析为 Unix 时间戳 格式:int strtotime ( string $time [, int $now ]...

php5 non-thread-safe和thread-safe这两个版本的区别分析

先从字面意思上理解,None-Thread Safe就是非线程安全,在执行时不进行线程(thread)安全检查;Thread Safe就是线程安全,执行时会进行线程(thread)安全检...

php md5下16位和32位的实现代码

复制代码 代码如下:<?php   echo substr(md5("admin"),8,16);  // 16位MD5...