当前位置:首页 > PHP教程 > php文件操作 > 列表

php 给文件尾部增加内容

发布:smiling 来源: PHP粉丝网  添加日期:2014-08-18 14:15:13 浏览: 评论:0 

如果我们想添加到一个文件,我们需要以追加方式打开它,下面的代码实现了这个功能,代码如下:

  1. $text = "test.txt"; 
  2. if( file_exists( $text ) && is_file( $text ) ) 
  3. { 
  4.  $fh = fopen($myFile, 'a'); 
  5.  if( $fh ) 
  6.  { 
  7.   $stringData = "New www.phpfensi.com 1 "; 
  8.   if( fwrite($fh, $stringData)) 
  9.   { 
  10.    echo '增加'.$stringData.'成功'; 
  11.   } 
  12.   else 
  13.   { 
  14.    die('文件不可写'); 
  15.   } 
  16.   $stringData = "New phpfensi.com 2 "; 
  17.   fwrite($fh, $stringData); 
  18.   fclose($fh); 
  19.  
  20.  } 
  21. } 

Tags: php文件尾部 php增加内容

分享到: