Hi all !
I've got a problem with replacing a String in a File with a new one.
For example i got a File called xyz.txt.
Within this File there is a Line like the following :
//REPLACE_ME
Now i want my PHP Script to find, and then replace this line with something like the following :
$TEST="true";
So i'll get a modified File at the end.
I tried the following code :
$handle = fopen ("../inc/Konstants.inc","r+");
while (!feof ($handle)) {
$buffer = fgets($handle,1024);
if (strpos($buffer,"//REPLACE_ME")>0) {
$buffer = str_replace("//REPLACE_ME","\$TEST=\"true\"",$buffer);
fwrite($handle, $buffer);
break;
}
}
fclose ($handle);
With this code the Line doesn't gets replaced - the new content which should replace the old line simply was written to the end of my file ...
I hope someone could help me with this.
Thanks in advance
Hotkey