PHP file read and write operation code

高洛峰
Release: 2023-03-01 12:40:01
Original
1117 people have browsed it

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; 
?>
Copy after login


Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!