Web Hosting Talk







View Full Version : text replacement help please


larwilliams
03-02-2008, 05:13 PM
Hi guys,

I am upgrading a server (for a client) to php5 that has about 75 small sites (php + basic forms and feedback). Some of these sites were coded back in the day and use the old $HTTP_GET_VARS, $HTTP_POST_VARS and $HTTP_SERVER_VARS.

I would rather not set register_long_arrays = On to be safe.

I have root access to the server and all sites are stored under /home.

Is there a way to automatically replace the above variables with the current ones ($_GET, $_POST, and $_SERVER) in every .php file. I know some combination of the find, sed, and xargs commands (shell) is needed, but not sure the syntax required.

If someone could post an example, it would be appreciated.

azizny
03-02-2008, 08:51 PM
Sure, you can use PHP with str_replace. You can also use command prompt in linux/unix (I don't know how, but it should be doable with one or two lines).

Peace,

foobic
03-02-2008, 09:23 PM
Not necessarily the most elegant way but you could do something like:
grep -lr HTTP_GET_VARS /home |grep "\.php" |xargs sed -ie "s/HTTP_GET_VARS/_GET/g"

sed, used like that, will create backup files named .phpe - once you're sure it's done you'll want to remove these, eg. with
find /home -name \*.phpe |xargs rm -f

Backup first, obviously, and you might also want to test on a small subdirectory, eg. /home/user/public_html/test

larwilliams
03-03-2008, 05:10 PM
Will that go through folders recursively?
Not necessarily the most elegant way but you could do something like:
grep -lr HTTP_GET_VARS /home |grep "\.php" |xargs sed -ie "s/HTTP_GET_VARS/_GET/g"

sed, used like that, will create backup files named .phpe - once you're sure it's done you'll want to remove these, eg. with
find /home -name \*.phpe |xargs rm -f

Backup first, obviously, and you might also want to test on a small subdirectory, eg. /home/user/public_html/test

foobic
03-03-2008, 05:17 PM
Yes (grep -r = recursive)

Metallian
03-03-2008, 08:14 PM
great, thanks i have same problem too :)