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+ajax实现无刷新分页

php+ajax实现无刷新分页

本文实例讲述了php+ajax实现无刷新分页实现方法。分享给大家供大家参考。具体如下:     limit  偏移量,长度;  &nbs...

simplehtmldom Doc api帮助文档

API Reference Helper functions object str_get_html ( string $content ) Creates a DOM object f...

一个php生成16位随机数的代码(两种方法)

分享一个php生成16位随机数的代码,php生成随机数的二种方法。 方法1 复制代码 代码如下: <?php $a = mt_rand(10000000,99999999)...

PHP实现可精确验证身份证号码的工具类示例

PHP实现可精确验证身份证号码的工具类示例

本文实例讲述了PHP实现可精确验证身份证号码的工具类。分享给大家供大家参考,具体如下: <?php class check_IdCard { // $num为身份证号...

php获取$_POST同名参数数组的实现介绍

今天写php的时候发现$_POST["arr"]无法获取参数arr的数组,记录一下。例如有以下表单需要提交:复制代码 代码如下:  <input type="checkbox" n...