Jump to content

Remove White Lines When Writing to a fil


glenelkins

Recommended Posts

please consider the following code

[code]
if (isset($_GET)) {
if ($_GET['a'] == "delete") {
$domain_id = $_GET['id'];

// Delete records from HTTPD
$sql = "SELECT domain FROM domains WHERE id='$domain_id'";
list ($domain) = mysql_fetch_array(mysql_query($sql));

$open_file = file($httpd_file);

// Loop through all lines until we find VirtualHost tag
for ($l=0;$l<count($open_file);$l++) {
if (strstr($open_file[$l],"<VirtualHost")) {
// Tag found, check for domain in next line
if(strstr($open_file[($l+1)],$domain)) {
$lines_to_delete = $l . "," . ($l+1) . "," . ($l+2) . "," . ($l+3) . "," . ($l+4);
}
}
}

// Seperate the lines to delete, then delete them
$lines_to_delete = explode(",",$lines_to_delete);
$content = "";
foreach ($open_file as $line_number=>$line) {
$found=0;
foreach($lines_to_delete as $ltd) {
if ($ltd == $line_number) {
$found=1;
}
}

if ($found == 0) {
$content .= $line;
}
}

// Write the contents back to the file
$open_file = fopen($httpd_file,"w");
fwrite($open_file,$content);
fclose ($open_file);

// Delete domain from database
$sql = "DELETE FROM domains WHERE id='$domain_id'";
mysql_query($sql) or die(mysql_error());

}
}
[/code]

this deletes a VirtualHost from httpd.conf for a selected domain. It works fine, except where the virtual host used to be, its now a bunch of blank lines...how do i remove the blank lines?
Link to comment
https://forums.phpfreaks.com/topic/31587-remove-white-lines-when-writing-to-a-fil/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.