I have a code in which should open an existing text file into my server, save the text into a variable, then filter the text contained within this variable and save again, as you can see below:
Text File:
Descrição: lorem impsum is a dollar do dolla do dolla style user humam
Source Code:
$filename = "prods/".$value;
$handle = fopen($filename, "w+");
$contents = fread($handle, filesize($filename));
$newcontent .= str_replace("Descrição:", "Descricao:", $contents);
fwrite($handle,$newcontent);
fclose($handle);
The problem is the command write is saving the file again with null text inside him, how can I solve this?