SafeY
12-22-2012, 08:03 AM
hey , I need a function which can take values from text boxes and save every value to the text file in certain place .
I did this but I used an external text file , I took what I need from the original file then put the new values nect to them in the helping file and then I copied it content to my original file .
my file :
Sally = 10
Sami = 50
I want it to be like this :
Sally = 1230
Sami = 23450
here's my old code :
if(file_exists($trID_Log_File) && filesize($trID_Log_File) > 0) {
$h = fopen($trID_Log_File, "r");
$contents = fread($h, filesize($trID_Log_File));
fclose($h);
$out_h = fopen("output filename", "w");
if(!stristr($contents, "TrID is best suited to analyze binary files!")) {
$lines = explode("\n", $contents);
foreach($lines as $line) {
if(strlen($line) > 5) {
$line_arr=explode("=",$line);
if ($line_arr[0]=='Sally') {
$line_arr[1]="10"; // The New Value
}
fwrite($out_h, implode("=", $line_arr)."\n");
}
}
}
}
so I'm writing to "output.txt" and then coping it back to my file , How can I do that ?
I did this but I used an external text file , I took what I need from the original file then put the new values nect to them in the helping file and then I copied it content to my original file .
my file :
Sally = 10
Sami = 50
I want it to be like this :
Sally = 1230
Sami = 23450
here's my old code :
if(file_exists($trID_Log_File) && filesize($trID_Log_File) > 0) {
$h = fopen($trID_Log_File, "r");
$contents = fread($h, filesize($trID_Log_File));
fclose($h);
$out_h = fopen("output filename", "w");
if(!stristr($contents, "TrID is best suited to analyze binary files!")) {
$lines = explode("\n", $contents);
foreach($lines as $line) {
if(strlen($line) > 5) {
$line_arr=explode("=",$line);
if ($line_arr[0]=='Sally') {
$line_arr[1]="10"; // The New Value
}
fwrite($out_h, implode("=", $line_arr)."\n");
}
}
}
}
so I'm writing to "output.txt" and then coping it back to my file , How can I do that ?