Jump to content

How to Read a File, Edit and Replace that file with new Changes?


robohelp

Recommended Posts

Hi

I am making a enhancement to our helpdesk product. So we are using JSON for saving the Language defaults. Now I am Using PHP as a server based language. Now here is the logic of the program. Whenever our product is installed then a parser will create a HTML file which will have all the defaults from the JSON file. Now when a user changes the language then the parser will again Run and make the required changes in the JSON file and again create the HTML file and Replace it in that folder. I am not able to find a good solution for this.

Can someone help me building it. I am not able to get how to Open a file, Read it, make the changes and Replace that file. I hope someone can help me in this regard.

Thanks

Lalit
Link to comment
Share on other sites

[CODE]
<?PHP if(!$_POST["new_html"]){ ?>
<form action="" method="post">
<textarea name="new_html"><?PHP echo str_replace("<", "&lt;", file_get_contents('file.html')); ?></textarea>
<input type="submit" value=" Save " />
</form>
<?PHP }
if($_POST["new_html"]){
$file = fopen('file.html', '+w') or die('Could not open file');
fwrite($file, $_POST["new_html"]);
fclose($file);
echo 'Changes saved';
}
?>[/code]
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.