July 13, 2010 | In: Coding Tips
Recursively search and replace content of files
I have encountered a problem when moving an old website to a newer server. Older website was using ‘HTTP_POST_VARS’ which is deprecated in PHP5 and there were thousands of files included older version variable. Here’s the solution using regular expression to swap ‘HTTP_POST_VARS’ to ‘_POST’ in all files under current & sub directories.
find ./ -type f | xargs perl -pi -w -e 's/HTTP_POST_VARS/_POST/g;'
* Or you can change the php.ini file (register_long_arrays=off) to use the deprecated long predefined variables, though it's not recommended.