I need a function just like preg_replace but instead of strings I need it to work with files / file content.
You can do:
$file = 'filename'; file_put_contents($file,str_replace('find','replace',file_get_contents($file)));