I tried to use fopen, but I only managed to append content to end of file. Is it possible to overwrite all contents with new content in PHP?
$fname = "database.php"; $fhandle = fopen($fname,"r"); $content = fread($fhandle,filesize($fname)); $content = str_replace("192.168.1.198", "localhost", $content); $fhandle = fopen($fname,"w"); fwrite($fhandle,$content); fclose($fhandle);