GiamDoc 7063
| Posté : 02-05-2004 12:10
transformes tes pages Php3 en php4 avec ce code nommes ce fichier:
php3tophp4.php
<?
class tab
{
var $tbRep;
var $tbFil;
function tab()
{
$this->tbRep = array();
$this->tbFil = array();
}
}
function getExt($dir) {
if (is_file($dir)) return substr($dir, strrpos($dir, '.')+1);
else return FALSE;
}
function getTree($dir) {
$tree=array();
$d=dir($dir);
while($entry=$d->read()) {
if ($entry <> ".." && $entry <> "." && $entry <>"php3ToPhp4.php")
{ $tree[]=$entry; }
}
$d->close();
return $tree;
}
function browseTree($dir, $tab) {
Global $dirOrig;
$tree=getTree($dir);
asort($tree);
while (list($key, $val)=each($tree)) {
// echo "\$tree[$key]==$val \n";
if (is_dir(($dir!='/')?$dir.'/'.$val:$dir.$val)) {
$tab->tbRep[]=($dir!='/')?$dir.'/'.$val:$dir.$val;
$tab = browseTree(($dir!='/')?$dir.'/'.$val:$dir.$val, $tab);
} else $tab->tbFil[]=($dir!='/')?$dir.'/'.$val:$dir.$val;
}
return $tab;
}
function replacePHP3($file)
{
//echo $file." ";
//$tmp = strrchr ($file, "/");
//echo $tmp." ";
if (!$fp = fopen($file,"r+"))
{
echo "echec d'ouverture du fichier ";
exit;
}
else
{
$tmp = fopen ("tempo", "a");
while (!feof($fp))
{
$ligne = fgets($fp,1024);
$ligne=str_replace(".php3",".php",$ligne);
fputs ($tmp, $ligne);
//echo $ligne." ";
}
fclose($tmp);
}
fclose($fp);
unlink($file);
rename("tempo", $file);
//unlink("tempo");
}
$twoTab = new tab();
$dirOrig='.';
$twoTab = browseTree($dirOrig, $twoTab);
reset($twoTab->tbRep); reset($twoTab->tbFil);
//echo " nb file ".sizeof($twoTab->tbFil)." ";
//echo " nb rep ".sizeof($twoTab->tbRep)." ";
for ($j=0;$jtbFil);$j++)
{
$tmp = "";
echo $twoTab->tbFil[$j]." ";
$tmp = strrchr ($twoTab->tbFil[$j], ".");
//echo $twoTab->tbFil[$j]." ".$tmp." apres la recherche de l'extension ";
if ($tmp == ".php3")
{
$tmp = str_replace(".php3", ".php", $twoTab->tbFil[$j]);
rename($twoTab->tbFil[$j],$tmp);
$twoTab->tbFil[$j] = $tmp;
}
//echo $tmp." ";
if($twoTab->tbFil[$j] != "php3tophp4.php")
replacePHP3($twoTab->tbFil[$j]);
}
?>
Message édité par : GiamDoc |