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

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -