Skip to content

Instantly share code, notes, and snippets.

@splacento-incomm
Created May 5, 2014 08:37
Show Gist options
  • Save splacento-incomm/6c376d285fc0a6e854ba to your computer and use it in GitHub Desktop.
Save splacento-incomm/6c376d285fc0a6e854ba to your computer and use it in GitHub Desktop.
Search and replace strings in all files in directory
<?php
// Copyright by Sebastijan Placento, 9a3bsp@gmail.com
// use this script on your own risk.
$dir= "/var/www/domain.com/web/templates/";
$search="/var/www/templates/";
$replace="/var/www/domain.com/web/templates/";
/**
DONT CHANGE PAST THIS COMMENT!
**/
$files=scandir($dir);
foreach($files as $file){
if($file=="." || $file=="..") continue;
// read the file
$f = file_get_contents($dir.$file);
// replace the data
$fileContent = str_replace($search, $replace, $f);
// write the file
file_put_contents($dir.$file, $fileContent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment