萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> PHP 文件操作類創建文件並寫入

PHP 文件操作類創建文件並寫入

   if (! empty ( $mode )) {

  $this->mode = $mode;

  }

  //判斷寫入的內容

  if (! empty ( $content )) {

  $this->content = $content;

  }

  $handle = fopen ( $this->path, $this->mode );

  //拆分換行

  $string = explode ( ",", $this->content );

  foreach ( $string as $v ) {

  fwrite ( $handle, $v . "rn" );

  }

  fclose ( $handle );

  }

  }

  //使用

  $log = new log ();

  // $log->addlog (); //不傳值 走默認值

  // $log->addlog ( "./log", "a", " 內容1:$content1 內容2: $content2 內容3: $content3 " ); //傳多個內容

  // $log->addlog ( "./log", "a", "123,123,123" ); //一次插入並換行

copyright © 萬盛學電腦網 all rights reserved