From 1b0e4b4cc0cb98b9b6b1c3b4bdd3d602af91a76a Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Wed, 27 Sep 2006 04:26:50 +0000 Subject: Do not leave trailing spaces before or after the text we are adding or removing. --- etc/inc/pfsense-utils.inc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'etc/inc') diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index 089f620..e203636 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -776,10 +776,14 @@ function add_text_to_file($file, $text) { if(file_exists($file) and is_writable($file)) { $filecontents = split("\n", file_get_contents($file)); $fout = fopen($file, "w"); - foreach($filecontents as $line) + $new_file_text = ""; + foreach($filecontents as $line) { if($line) - fwrite($fout, rtrim($line) . "\n"); - fwrite($fout, rtrim($text) . "\n"); + $new_file_text .= rtrim($line) . "\n"; + } + $new_file_text .= $text . "\n"; + $file_text = str_replace("\n\n", "\n", $new_file_text); + fwrite($fout, $file_text); fclose($fout); return true; } else { -- cgit v1.1