There are two files on my server,
- balance.php
- balance.txt
balance.txt file contains following data;
jhon==>20000==>present
tom==>50000==>present
karissa==>55000==>present
ryan==>25000==>present
bob==>45000==>present
PHP script is, scan for username and once username found (explode is used), add 10000 to its balance amt (next to username);
<?php
$user = "bob"; //searching for bob
$salary = 10000; //want to add 10K in his balance
$scan = fopen("balance.txt","w+");
while (!feof($scan)) {
$eachline = fgets($scan);
$eachline = explode ("==>",$eachline);
if ($eachline[0]== $user){
$oldAmt = $eachline[1];
$newAmt = $oldAmt + $salary;
echo "Username : ".$user;
echo "Old Amount: ".$oldAmt;
echo "New Amount: ".$newAmt;
\\Now write $newAmt in place of $oldAmt, in balance.txt file.
\\HOw can I do this in easy way?
}
}
fclose($recon);
?>
Now, replace $scan[1] with $amt. What is the easiest way to do this?