Hello
I'm having a big problem trying to replace a string (update) a text file.
Username and Password are written to a text file. I want to update the file when user changes their password.
The following code works fine with str_replace() and eregi_replace() except that when writing to the file it eliminates all other entries, or in append mode it simply adds a line leaving the old line intact.
I have also tried to explode() the file into an array but only succeed in crashing my browser during the loops and get a "Resource id #3" notice (what does that mean? I get that from time to time but cannot find a suitable answer).
Anyway, thank you for your help.
Richard
<?php
$filename = "cust_info.txt";
$file = fopen($filename,"a");
$username = "monkey";
$oldpassword = "banana";
$newpassword = "yowl";
$string = "Username = $username Password = $oldpassword";
$pattern = "Password = $oldpassword";
$replacement = "Password = $newpassword";
$newpattern = str_replace($pattern,$replacement,$string);
echo $newpattern;
fwrite($file, "$newpattern\n\n");
fclose($file);
?>