Last active
January 30, 2021 13:46
-
-
Save mpdroog/32eabf0556f0d316d2d4bd38793c075e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Search&Replace all occurrences of a given string | |
// Got tired of all the harship with sed -i so made this | |
// small script to get the same result. | |
$search = "Fn"; | |
$replace = "Shared"; | |
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.')); | |
foreach ($rii as $file) { | |
if (in_array($file->getFilename(), [".", "..", "findreplace.php", ".git"])) continue; // Ignored files (in curdir) | |
if (strpos($file->getPath(), ".git") !== false) continue; // Ignore everything in the .git dir | |
if (strpos($file->getFilename(), ".php") === false) continue; // Only parse .php files | |
$content = file_get_contents($file); | |
if (strpos($content, $search) !== false) { | |
var_dump($file); | |
$content = str_replace($search, $replace, $content); | |
file_put_contents($file, $content); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment