Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class CSV
- {
- private $filename ;
- private $lines ;
- function __construct($filename)
- {
- $this->filename = $filename;
- $this->LoadFile();
- }
- private function LoadFile()
- {
- if (file_exists($this->filename) && filesize($this->filename) > 0 && $fp = @fopen($this->filename, 'r'))
- $this->lines = explode("\n", fread($fp, filesize($this->filename)));
- else
- echo ("file not found");
- }
- public function GetLast()
- {
- if ($this->Count() > 0)
- return $this->lines[$this->Count() - 1];
- else
- return NULL;
- }
- public function DeleteLast()
- {
- if (is_array($this->lines) && $this->Count() > 0)
- array_pop($this->lines);
- }
- public function Save()
- {
- if ($fp = @fopen($this->filename, 'w'))
- {
- for ($i = 0 ; $i < $this->Count() ; $i++)
- fwrite($fp, $this->lines[$i] . ($i == $this->Count()-1 ? "" : "\n"));
- fclose($fp);
- }
- }
- public function Count()
- {
- if (is_array($this->lines))
- return count($this->lines);
- else
- return 0;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement