How would i go about making a script like this?

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
I want the script to search through a file, and find the part that is typed out, and then replace it with another input.

Is this how i would go about doing it?

Anyways thanks in advance.

<?


$myFile = fopen("c:\www\dittohost\\test.txt", "a");
$fcontents = file($myFile);

str_replace($oldpassword,$newpassword,$i_dont_know_what_to_put_here);

fclose($myFile);

?>
 

kt

Diamond Member
Apr 1, 2000
6,031
1,346
136
it should be..

$fcontents = str_replace($oldpassword,$newpassword,$fcontents);


be aware that will only work if your PHP is 4.0.5 or later. That's because if there are multiple lines in the file, then $fcontents is an array of string. Each of the array element is a line in the file. In earlier versions of PHP, str_replace do not support arrays in the the parameter. So, you'll need to put the above line in a FOR loop.

btw, from what I can tell you are storing passwords in a textfile.. it's generally a bad idea to do so. It's worst if you store them as plain text. At least do some encryption on the password. Encrypt the password with MD5 or something. MD5 is one-way encryption though, meaning once you encrypt a string you can't decrypt it back.