summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorScott Ullrich <sullrich@pfsense.org>2007-05-02 22:36:26 +0000
committerScott Ullrich <sullrich@pfsense.org>2007-05-02 22:36:26 +0000
commit5a6f3ca0afa353260c9911458faf03f91d16b65b (patch)
tree8596e1101714fc051254d64a218cd34822200080 /etc
parentb1ed535678dfb06ba9fa82e0e0020ce8ca6aef31 (diff)
downloadpfsense-5a6f3ca0afa353260c9911458faf03f91d16b65b.zip
pfsense-5a6f3ca0afa353260c9911458faf03f91d16b65b.tar.gz
* Do not allow duplicate entries by default in add_text_to_file() * Add option which allows duplicates Submitted-by: Uranellus via IRC
Diffstat (limited to 'etc')
-rw-r--r--etc/inc/pfsense-utils.inc19
1 files changed, 10 insertions, 9 deletions
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc
index 14f8b93..d8b8b98 100644
--- a/etc/inc/pfsense-utils.inc
+++ b/etc/inc/pfsense-utils.inc
@@ -1536,17 +1536,18 @@ function remove_text_from_file($file, $text) {
* add_text_to_file($file, $text): adds $text to $file.
* replaces the text if it already exists.
*/
-function add_text_to_file($file, $text) {
+function add_text_to_file($file, $text, $replace = false) {
if(file_exists($file) and is_writable($file)) {
- $filecontents = split("\n", file_get_contents($file));
+ $filecontents = file($file);
$fout = fopen($file, "w");
- $new_file_text = "";
- foreach($filecontents as $line) {
- if($line)
- $new_file_text .= rtrim($line) . "\n";
- }
- $new_file_text .= $text . "\n";
- $file_text = str_replace("\n\n", "\n", $new_file_text);
+
+ $filecontents = array_map('rtrim', $filecontents);
+ array_push($filecontents, $text);
+ if ($replace)
+ $filecontents = array_unique($filecontents);
+
+ $file_text = implode("\n", $filecontents);
+
fwrite($fout, $file_text);
fclose($fout);
return true;
OpenPOWER on IntegriCloud