you'll have to read the file handling documentation ... your approach is wrong.
look up: fopen, fread, fwrite, fclose; file, and browse through the readers' postings; they containg valuable examples.
concretely, you're mixing up file handlers ($fp) with the actual data that you can retrieve with fread. in addition to that, you'll have to write back the manipulated data to the file (fwrite).
hope this gets you on the way!