Issue
I have to change a couple of thousand lines of code. Looking for a quick way ;)
Code in PHP $lang[_SAVE] to be altered to $lang['_SAVE']
I need to find [_ and replace it with ['_ and then replace next ] with ']
regex from cmd line in debian would be prefered ;)
EDIT: I need to replace whats between $lang[_
and ]
with '<string between $lang[_ and ]>'
Solution
Fixed it with:
<?php
$it = new RecursiveDirectoryIterator(".");
// Loop through files
foreach(new RecursiveIteratorIterator($it) as $file) {
if ($file->getExtension() == 'php') {
$content=file_get_contents($file);
$found = preg_replace('/(?<=lang\[)(_.*?)(?=])/', "'$1'", $content);
file_put_contents($file, $found);
}
}
?>
with a bit of help of https://www.phpliveregex.com/#tab-preg-replace
It traverse the files recursively and looks for whats between lang[_
and next ]
and replaces that value with '<found value>'
Answered By - osomanden Answer Checked By - Cary Denson (WPSolving Admin)