Home >Backend Development >PHP Tutorial >PHP file read and write operation code

PHP file read and write operation code

高洛峰
高洛峰Original
2016-11-30 11:55:061187browse

The code is as follows:

<?php 
//打开文件 
$fp=fopen(&#39;tmp.html&#39;, &#39;r&#39;); 
//读取文件内容 可以用以下两个函数进行操作 fread,file_get_contents 
$str=fread($fp, filesize(&#39;tmp.html&#39;)); //filesize为获取文件大小 
$content=file_get_contents(&#39;tmp.html&#39;); 
//写文件 
$news=fopen(&#39;news.html&#39;, &#39;w&#39;); 
fwrite($news, $content); 
//关闭文件流 
fclose($fp); 
fclose($news); 
echo $content; 
?>


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