How to delete a line from a .TXT file? (PHP)?

DramaGeek

New member
I have a userinformation text file. When the user changes his information via submit form. I want it to delete his old information in the file and replace it with the new info. I don't have a reat example of code because obviously my idea wasn't working.. But This is what I tried to do:

$file = "login.txt";
$handle=fopen("login.txt","r+"); // open file and make it readable and writable
$file_array =file($file); //break file up into arrays
do {
$replace =stristr($file_array[$i],$user); // compare strings to find user's information
if ($replace) { // if match found, replace line with new data
str_replace($file_array[$i],$newdata,$file);
$info1 = explode(",", $data); // Explode new data so it will list in textboxes below

echo "You have updated your information!<br />";
echo '
// this displays the user's new information
<form name="input">
<br />
User Name:
<input type="text" name="user"value="'.$info1[0].'"/>
Password:
<input type="text" name="password"value="'.$info1[1].'"/>
Name:
<input type="text" name="name"value="'.$info1[2].'" /><br />
Address:
<input type="text" name="address1"value="'.$info1[3].'"/>
<input type="text" name="address2"value="'.$info1[4].'"/>
<br />
City:
<input type="text" name="city"value="'.$info1[5].'" /><br />
State:
<input type="text" name="state"value="'.$info1[6].'" /><br />
Zip:
<input type="text" name="zip"value="'.$info1[7].'" /><br />
Phone Number:
<input type="text" name="phone" value="'.$info1[8].'"/><br />
<!--update entry if user made changes.--></form>';
fclose($handle);}
$i++;
} while ($i<=1);
exit;//close file
}
I haven't used my sql because my programming class hasn't fully learned it yet.
 
Back
Top