Jump to content

FOPEN other options outside R W A....


Michael4172

Recommended Posts

What I'm wanting to do sounds very simple but the options I know of and have searched for haven't lead to an answer yet.

Basically I'm trying to find a method within FOPEN, to just replace a character or number within the line. I know W (write) would simply write over the existing information, and A (append) would just add to the file at the end. Is there some happy medium where I can change say one character or number within the file and leave the rest of the file as is?

Link to comment
Share on other sites

If you want to edit something in a file then you'll want to get the contents of the file, apply the changes and then rewrite the file.

You will want to use fopen, fread, str/preg_replace or other functions and then fwrite and fclose.
Link to comment
Share on other sites

You cannot edit inside a file you can only append to or rewrite the whole entire file.

That is why I said to use [a href=\"http://uk.php.net/manual/en/function.fread.php\" target=\"_blank\"]fread[/a] which you can then you add the contents of the file into a variable. Then use str/preg_replace to do the changes and use fwrite to rewrite the file with changes.

For example you have a file called test.txt with the following text init:
[code]this sentance has a mistake in it[/code]
Now you want to change the sentace to something else. You will do that by doing the following:
[a href=\"http://pastebin.com/705891\" target=\"_blank\"]click to see code[/a]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.