On Wed, Jun 1, 2011 at 6:26 PM, Merlin Morgenstern <merlin_x@xxxxxxxxxxx>wrote: > Hi there, > > I am working on a pretty huge site with thousands of files with php code. > Unfortunatelly the app throws a ton of notices du to missing '' in arrays. > Of course I could simply disable the output on the dev server to surpress > notices, but I would rather like to get it fixed. > > Has somebody a good idea on how to fix this automated somehow with regex? > > The vars are right now: $var[element] and should be $var['element'] > > I was looking into sed, but I was hoping that there is also a way in php. > Has anybody a hint on how to get the regex done? > > I appreciate any help on that. > > Best regards, > > Merlin > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > I'd use the DirectoryIterator to work through the site and locate all of the php files: http://www.php.net/manual/en/directoryiterator.isfile.php <http://www.php.net/manual/en/directoryiterator.isfile.php>And, once I find a file, I'd perform a preg_replace such as below: $php = '$var[element]'; $re_patterns = array( '/^(\$[a-zA-Z0-9]+\[)([a-zA-Z0-9]+)(\])$/' ); $re_replaces = array( '\1"\2"\3' ); // preg_replace can return null, so must make sure php isn't lost echo $php = (($temp_php = \preg_replace($pattern = $re_patterns, $replacement = $re_replaces, $subject = $php)) !== null) ? $temp_php: $php; I'm confident you can easily use PHP to do this, and hopefully this info is enough to get you started. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com