File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes PHP and the fly likes PHP replacing new value in a text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » PHP
Bookmark "PHP replacing new value in a text file" Watch "PHP replacing new value in a text file" New topic

PHP replacing new value in a text file

Abhradeep Banerjee
Ranch Hand

Joined: Dec 09, 2009
Posts: 71
I have only put the PHP code I dont think HTML is needed as its quite a standard form.
I am kind stuck here. What i need to is everytime a user enters the no of oranges, apples and bananas this value be added on to what ever value there is in the text file currently.

in the text file if the user submits for the first time it will print out in the example below:

The total Number of Apples: 10
The total Number of Bananas: 10
The total Number of Oranges: 10

subsequent submission it will add on to the new value entered and it will replace the value 10 in this case.

Can someone assist in solving this problem?

K. Tsang

Joined: Sep 13, 2007
Posts: 3132

Well first you need to "read" the values and add the new value

K. Tsang JavaRanch SCJP5 SCJD OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1 part 2/3
sourav jain

Joined: Nov 19, 2012
Posts: 22

i have made class for insert the total number of apples, banana, oranges in file , i am using static variable instead simple variable. static variable preserve value all time .

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>



class ABC

static $totalorange='';
static $totalbnana='';
static $totalapples='';
static $total='';
static $totalitems='';

function fun($apples,$bannas,$oran)

global $totalorange,



echo $total=$total+$totalitems;


fwrite($file,"the total oranges is".$totalapples);




$obj =new ABC;

Ashton Cohen

Joined: Dec 02, 2014
Posts: 1

Did you ever get your edit fruit quantity PHP code /page going?

Can you share the final code please.

I'm having trouble applying the above snippets to a form based on a 4-line text file to a quantity-edit web form project similar to yours maybe.


I agree. Here's the link:
subject: PHP replacing new value in a text file
It's not a secret anymore!