File to read * */ public static function read($file){ /* [1] Init driver =========================================================*/ $driver = new \SplFileObject($file, 'r'); /* [2] Read lines =========================================================*/ $read = ''; /* (1) Reads lines */ $line = 0; while( $driver->current() ){ $read .= "\n".$driver->current(); $driver->next(); } /* [3] Returns read content =========================================================*/ /* (2) Destroy driver */ $driver = null; /* (3) Returns result */ return $read; } /* WRITES CONTENT TO A FILE * * @file File to write to * @content Content to write * */ public static function write($file, $content){ /* (1) Erase file */ file_put_contents($file, ''); /* (2) Get driver (write-flag) */ $driver = new \SplFileObject($file, 'r+'); /* (3) Writes content */ $driver->fwrite($content); /* (4) Free driver */ $driver = null; } /* APPENDS CONTENT TO A FILE * * @file File to append content to * @content Content to append * */ public static function append($file, $content){ /* (1) Get driver (append-flag) */ $driver = new \SplFileObject($file, 'a'); /* (2) append content */ $driver->fwrite($content.PHP_EOL); /* (3) Free driver */ $driver = null; } } ?>