Home >php教程 >PHP源码 >php读写文件函数

php读写文件函数

WBOY
WBOYOriginal
2016-06-08 17:26:531382browse

我们在php中用读写函数都会用到fopen与fwrite来实例,下面我们来看二个简单的实例吧。

<script>ec(2);</script>

//读取数据函数

 代码如下 复制代码
function readover($filename)
{
 $file=fopen($filename,"r");
 flock($file,LOCK_SH);
 $filedetail=fread($file,filesize($filename));
 fclose($file);
 return $filedetail;
}

下面是写入文件


//写入数据函数

 代码如下 复制代码
function writeover($filename,$data,$method="w")
{
 $file=fopen($filename,$method);
 flock($file,LOCK_EX);
 $filedetail=fwrite($file,$data);
 fclose($file);
 return $filedetail;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn