if (file_exists($this->file) && is_readable($this->file) && is_writable($this->file)) { echo $this->file . "\n\n"; $contents = file_get_contents($this->file); $foo = preg_replace($this->search, $this->replace, $contents); file_put_contents($this->file, $contents); return true; } else { ... }