摘要:php文档写入有三种方式 第一种是使用fwrite() 第二种 fputcsv() 第三种file_put_contents()fwrite()和fputcsv()是需要打开文档的,file_put_contents()不需要,但如果是数组的方式写入是需要序列化打开文档时用fopen() 关闭文档fclose() 重命名文档 rename() 创建一个文档是用 touch() 删除是
php文档写入有三种方式 第一种是使用fwrite() 第二种 fputcsv() 第三种file_put_contents()
fwrite()和fputcsv()是需要打开文档的,file_put_contents()不需要,但如果是数组的方式写入是需要序列化
打开文档时用fopen() 关闭文档fclose() 重命名文档 rename()  创建一个文档是用 touch() 删除是 unlink()
拷贝是copy() 可以拷贝网上的内容
<?php
//打开文件
$file = fopen('demo.txt','r');
//读取内容
echo fread($file,15);
//指针所在的位置
echo ftell($file);
//指针归零
echo rewind($file);
//关闭文件
fclose($file);
//1.创建文件
$file = 'demo02.txt';
echo touch($file) ? '创建成功' : '失败';
删除文件
if(file_exists($file)){
    echo '文件存在'.'<br>';
    echo unlink($file) ? '删除成功' : '删除失败';
}else{
    echo '没有此文件';
}
echo '<br>';
//修改文件名
echo rename($file,'rename.txt') ? '修改成功':'失败';
//拷贝文件
echo copy('https://www.google.com.hk/','copy1.html') ? '拷贝成功' : '拷贝失败';
//打开文档
$file = fopen('demo.txt','wb+');
//写入
echo fwrite($file,'我是头猪我是头猪我是头猪我') ? '写入成功' : '写入失败';
echo '<br>';
//指针归零
rewind($file);
//读取文件
echo fread($file,filesize('demo.txt'));
//关闭文件
fclose($file);
?>
						批改老师:天蓬老师批改时间:2018-12-27 17:07:14		
						
老师总结:文件操作非常多,而且与C语言中的几乎是一样的,因为php就是用c语言写的					
 
                 
 
 
  
            