Re: Deleting a String from a file.
| From: | CPT John W. Holmes | Date: | Fri, 21 Nov 2003 22:24:55 +0000 |
| Subject: | Re: Deleting a String from a file. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-170629@lists.php.net to get a copy of this message | ||
From: "Cameron Badgley" <autocautiondoor@hotmail.com>
> Hey, I'm trying to write a script which deletes a String from a file. The
> String that the user wants deleted is provided from a form and the file is
> named to2do.txt. I have a hidden variable called "deleting" that lets me
> know when the string has been submitted.
>
> I have written the following code but receive the error:
> Warning: fclose(): supplied argument is not a valid File-Handle resource
in
> /u3/7/cirop27/public_html/todo/to2doDEL.php on line 63
[snip]
> $mfile = fopen("to2do.txt",'r+');
This opens the file and makes $mfile a file handle, but it does not read it.
>
> //delete the string
> $mfile = str_replace($msg, "", $mfile);
You're overwriting the file handle here by using the same variable.
> /*** error occurs here ***/
> fclose($mfile);
You also need to write the new data to the file...
fread(), fwrite(), etc...
---John Holmes...