PDA

View Full Version : Convert php3 to php


SloppyGoat
03-22-2003, 06:39 PM
I found this code that will convert php3 to php, but I can't get it to work. I'm no expert on this stuff, but I'd love for this to work. I'm thinking I may just have to change the top line, but what do I change it to, if so? Can someone take a look and tell me what you think? Is that top line supposed to map to my php folder? Maybe I just need to change the path? But what's "#!" mean? I'm running a IIS server, so if that's Apache stuff, I'm not real familiar with it.

#!/usr/bin/php -q
<?php
// Convert .php3 to .php
// ( and internal refs )
//
function doFile($var) {
if (substr($var,strlen($var)-4,4) == "php3") {
$orig = $var;
$new = substr($orig,0,strlen($orig)-1);
$cmd = "sed 's/php3/php/g' $orig > $new;rm -f $orig";
$res = exec($cmd,$res);
echo "Orig: $orig\\tNew: $new\\n";
} else {
echo "--Skipping: $var\\n";
}
}
$dir=(is_array($argv) && $argv[1]) ? $argv[1] : ".";
$a = `find $dir -depth -type f -print`;
$files = explode ("\\n", $a);
echo "Files: ".count($files)."\\n";
foreach($files as $item) {
doFile($item);
}
echo "Done.\\n";
?>

USAGE:
save this code as phpconvert
chmod 700 phpconvert

* put in topmost directory of entire structure to be converted ie:
if when you extracted test.zip, it made a structure like this:
/home/myname/www/test
/home/myname/www/test/admin
/home/myname/www/test/configs
/home/myname/www/test/configs/lang
/home/myname/www/test/configs/lang/english
/home/myname/www/test/configs/lang/german
/home/myname/www/test/includes

put phpconvert into your /home/myname/www/test directory:
(cp phpconvert /home/myname/www/test)
change into that directory:
cd /home/myname/www/test

run it, sit back & enjoy the show:
./phpconvert .

It will recurse through all child directories & convert all references
to .php3 inside the files, to .php. Then save the new file as .php
and finally delete the original .php3 file.

If you ever need to be able to do this, at least now you have an easier way to handle it.
Don't know about you, but I sure could've used a script like this YEARS ago...
NOTE For some reason, it won't work correctly if you put this file in your path & try to call it from there ( ie /sbin/phpconvert)... instead, it tries to do it to all files in /sbin.
I'll fix it when I have time... For now, I'm just glad it saves me hours of unnecessary work.

SloppyGoat
01-15-2004, 07:19 PM
Nobody? :ermm: