I'm trying to change values in atext file after "=", explode returns an array of two elements, I want the second element to be replaced with a new value and then written in my file, but I'm lost with syntax !!
$trID_Log_File = $fileName;
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);
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($h,$line_arr,"w+") ; // ?????????
}
}
}
}
}
input :
sally= 10
samy=40
desired Output :
sally=55
samy=123
what's the right syntax for this problem !! am I missing some code ?? thanks