|
|
@@ -587,4 +587,31 @@ class File {
|
|
|
return clearstatcache();
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Searches for a given text and replaces the text if found
|
|
|
+ * @param string $search
|
|
|
+ * @param string $replace
|
|
|
+ * @return boolean Success
|
|
|
+ */
|
|
|
+ public function replaceText($search, $replace) {
|
|
|
+ if (!$this->open("r+")) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->lock !== null) {
|
|
|
+ if (flock($this->handle, LOCK_EX) === false) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $replaced = $this->write(str_replace($search, $replace, $this->read()), "w", true);
|
|
|
+
|
|
|
+ if ($this->lock !== null) {
|
|
|
+ flock($this->handle, LOCK_UN);
|
|
|
+ }
|
|
|
+ $this->close();
|
|
|
+
|
|
|
+ return $replaced;
|
|
|
+ }
|
|
|
+
|
|
|
}
|