首页  >  文章  >  php教程  >  php 给文件尾部增加内容

php 给文件尾部增加内容

WBOY
WBOY原创
2016-06-08 17:27:081294浏览

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


If we want to add on to a file we need to open it up in append mode. The code below does just that.

*/
 代码如下 复制代码

$text = "test.txt";
if( file_exists( $text ) && is_file( $text ) )
{
 $fh = fopen($myFile, 'a');
 if( $fh )
 {
  $stringData = "New www.111cn.net 1 ";
  if( fwrite($fh, $stringData))
  {
   echo '增加'.$stringData.'成功';
  }
  else
  {
   die('文件不可写');
  }
  $stringData = "New 111cn.net 2 ";
  fwrite($fh, $stringData);
  fclose($fh);

 }
}

if( file_exists( $text ) && is_file( $text ) ) {
 代码如下

复制代码

$text = "test.txt";
 $fh = fopen($myFile, 'a');<script>ec(2);</script>  if( $fh )  {   $stringData = "New www.111cn.net 1 ";   if( fwrite($fh, $stringData))   {    echo '增加'.$stringData.'成功';   }   else   {    die('文件不可写');   }   $stringData = "New 111cn.net 2 ";   fwrite($fh, $stringData);   fclose($fh);  } } /* 本站原创教程转载注明来源于www.111cn.net */
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn