/** * @access protected * @param string log record string * @return void */ protected function writeRecord($logRecordString) { $fileWriterObject = new FileWriter($this->getFileObject(), 'a'); $fileWriterObject->write($logRecordString); }
/** * @return void */ public function testClear() { $filePath = __DIR__ . '/example_write1.txt'; $fileObject = new FileWriter($filePath, 'a+'); $fileObject->clear(); $filePath = __DIR__ . '/example_write2.txt'; $fileObject = new \SplFileObject($filePath, 'a+'); $fileObject->ftruncate(0); }
/** * @access protected * @param string log record string * @return void */ protected function writeRecord($logRecordString) { $fileWriterObject = new FileWriter(ini_get('error_log'), 'a'); $fileWriterObject->write($logRecordString); }
echo '<br/>'; $string = 'Line01' . PHP_EOL; $string .= 'Line02' . PHP_EOL; $string .= 'Line03' . PHP_EOL; $string .= 'Line04' . PHP_EOL; $fileObject->write($string); foreach ($fileObject as $line) { echo $line . '<br/>'; } echo '<br/>'; //Line01 //Line02 //Line03 //Line04 $filePath = __DIR__ . '/example_write.txt'; $fileObject = new FileWriter($filePath, 'a+'); // file point at the end of the file $fileObject->writeLine("foo"); $fileObject->writeLine("bar"); foreach ($fileObject as $line) { echo $line . '<br/>'; } echo '<br/>'; //Line01 //Line02 //Line03 //Line04 //foo //bar $fileObject->clear(); // remove all content