How can I read through a file and find a string and then replace it with a
new string and then save the whole file.

Below is a peace of what I need to search through. I need to find the string
subscribe_policy = open and replace it with subscribe_policy = open+confirm.
Then save the whole file.

I have tried str_replace but it just wipes out the original file.

$file = "/var/lib/majordomo/domain.com/lists/listname.config";
$fp = fopen("$file", "w+");
$content = fread($fp, filesize($file));
$replace= "subscribe_policy =  open+confirm";
$search_str = "subscribe_policy =  open";
$content2 = str_replace($search_str,$replace, $content);
fwrite($fp,$content2);
fclose($fp);

# restrict_post        [restrict_post] (autoupdates) <resend>
# If defined, only addresses listed in these files (colon or space
# separated) can post to the mailing list. By default, these files
# are relative to the lists directory. These files are also checked
# when get_access, index_access, info_access, intro_access,
# which_access, or who_access is set to 'list'. This is less useful
# than it seems it should be since there is no way to create these
# files if you do not have access to the machine running resend.
# This mechanism will be replaced in a future version of
# majordomo/resend.
restrict_post = autoupdates.posters

# subscribe_policy     [enum] (open) <majordomo> /open;closed;auto;op
# One of three values: open, closed, auto; plus an optional
# modifier: '+confirm'.  Open allows people to subscribe themselves
# to the list. Auto allows anybody to subscribe anybody to the list
# without maintainer approval. Closed requires maintainer approval
# for all subscribe requests to the list.  Adding '+confirm', ie,
# 'open+confirm', will cause majordomo to send a reply back to the
# subscriber which includes a authentication number which must be
# sent back in with another subscribe command.
subscribe_policy = open

# unsubscribe_policy   [enum] (closed) <majordomo> /open;closed;auto/
# One of three values: open, closed, auto.  Open allows people to
# unsubscribe themselves from the list. Auto allows anybody to
# unsubscribe anybody to the list without maintainer approval. The
# existence of the file <listname>.auto is the same as specifying
# the value auto.  Closed requires maintainer approval for all
# unsubscribe requests to the list. In addition to the keyword, if
# the file <listname>.closed exists, it is the same as specifying
# the value closed. The value of this keyword overrides the value
# supplied by any existent files.
unsubscribe_policy = open

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to