I would first read the file into an array of lines and look at each line to see if it is the line you're looking for.
For example, assume we're looking for "Options" line and want to add "+ExecCGI":
$lines = file($filename);
$i = 0;
foreach ($lines as $line) {
if (ereg("^Options ", $line)) {
$options_line = $i;
print "Found the line";
} else {
print "Line not found";
}
$i++;
}
// create an array of the current options
$options = explode(" ", eregi_replace("options ", "", $lines[$options_line]));
// see if the option +ExecCGI already exists
foreach ($options as $option) {
if ($option == "+ExecCGI") {
$found = TRUE;
break;
}
}
// if it doesn't exist, add it
if (!$found) {
push_array("+ExecCGI", $options)
$lines[$options_line] = implode(" ", $options);
$fcontents = implode("\n\r", $lines);
// write the file
$fp = fopen ($filename, "aw");
fputs ($fp, $fcontents);
}
Hope this helps.
Lacey