php - find string in file on server and replace it -
i made script in .php find appearances of code( in case javascript code <script> tags), , replace else, on live server.
something grep -rnw '/path/to/somewhere/' -e "pattern" .
my question : how run .php script on server search files on server string , replace other string.
on desktop i've coded , worked : `
<?php $what = <<<eod <script>bla bla string</script> eod; $with=" "; $path_to_file = '/users/michael/desktop/results-prod.txt'; $file_contents = file_get_contents($path_to_file); $file_contents = str_replace($what,$with,$file_contents); file_put_contents($path_to_file,$file_contents); ?> and need live server , files(more 1 , using different paths).
thanks, michael!
$find = "your mom"; $replace = "your dad"; $dir= "/path/to/dir"; $files = scandir($dir); foreach($files $file){ if($file == "." || $file == "..") continue; $path = "$dir/$file"; $file_contents = file_get_contents($path); $file_contents = str_replace($find,$replace,$file_contents); file_put_contents($path,$file_contents); }
Comments
Post a Comment