I want to make a script that deletes a certain word from a txt file. I have a flash chat, and when you press logout, it runs a script on php. Here is the entire logout.php file:
I want to make a script that deletes a certain word from a txt file. I have a flash chat, and when you press logout, it runs a script on php. Here is the entire logout.php file:
string str_replace(string word, string replacement, string loginfile);
where "word" is the word you want to find in your file, "replacement" is what you want to replace it with, and "loginfile" is the string that contains the contents of your login file. In other words, read the login file first and assign the contents of it to a string variable. Then search for the word you want to replace inside of the loginfile string using the string replace function above and then write the content of the login file back to the file.
Ok, ive just banged up a quick script which works. Here goes:
PHP Code:
// Get the contents of the file as a string.
$fp = fopen($chat_file, "r");
$file = fgets($fp);
fclose($fp);
/* Open the file again with an overwriting mode, search for the desired nickname and replace with nothing (or something else). Put the new content into the file, then close it.
*/
Uploaded the wrong file... I get this error with your script anyways:
[02-Nov-2003 22:33:30] PHP Warning: fgets(): supplied argument is not a valid stream resource in /home/jjs47z/public_html/newchat/logout.php on line 5
[02-Nov-2003 22:33:30] PHP Warning: fclose(): supplied argument is not a valid stream resource in /home/jjs47z/public_html/newchat/logout.php on line 6
[02-Nov-2003 22:33:30] PHP Warning: fputs(): supplied argument is not a valid stream resource in /home/jjs47z/public_html/newchat/logout.php on line 14
[02-Nov-2003 22:33:30] PHP Warning: fclose(): supplied argument is not a valid stream resource in /home/jjs47z/public_html/newchat/logout.php on line 15
BTW, the TXT file is just a normal notepad file, and it is chmodded to 777
__________________
Over 5 years in design. www.webatech.com www.tabscentral.com/temp/
Make sure the txt file is chmod 0777. Theres nothing wrong with my script, I don't get those errors on my server (running v4.3.3). Try changing the names of the $fp variables. You have two so name the first one $fp1 and the second one $fp2. If that doesn't work try unset()ing the first $fp, after the fclose().