码迷,mamicode.com
首页 > Web开发 > 详细

php 文件操作

时间:2017-02-24 19:26:35      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:读取   echo   文件   doc   read   txt   文件操作   etc   get   

<!DOCTYPE html>
<body>
<html>

<?php
//echo readfile("file.txt");
$fp=fopen("file.txt","x") or die("Unable to open file!");//fopen用于打开和创建文件

// echo fread($fp,filesize("file.txt"));
/* while(!feof($fp)) //f end of file
{
//echo fgetc($fp)."<br>"; 读取单个字符
echo fgets($fp)."<br>"; //读取行
}*/


$txt="有你";
fwrite($fp,$txt);//r+写入的文件会覆盖原文件的内容,其余的内容不变,写完文件的指针指向了覆盖后的地方
//w w+写入的内容会完全覆盖原文件的内容,写完文件指针指向了文件的尾部
//a a+在原有的文件上的尾部写,写完文件指针指向了尾部
// x 若文件已经存在,返回错误,不存在就创建文件,返回正确
while(!feof($fp)) //f end of file
{
echo fgets($fp)."<br>";
}
fclose($fp);
?>
</body>
</html>

php 文件操作

标签:读取   echo   文件   doc   read   txt   文件操作   etc   get   

原文地址:http://www.cnblogs.com/jiangger/p/6439809.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!