Dear Friends
While dealing with template file, it is too common to make copies of that file and replace one word by another word.
In the code attached below one file is created dynamically based on table name and then a local copy of template file is created in the name of table in a folder HUP. Then a word HHHUUUPPP will be replaced with the name of table. Once the entire file is replaced then a fresh copy the new file will be taken and old file will be deleted.
//Code starts here.
<?php
$table=$_POST['tablename'];
$viewfile1='HUP/view'.$table.'1.php';
$viewfile='HUP/view'.$table.'.php';
copy('HUPViewtable.php',$viewfile1);
$myfilemain=fopen($viewfile, "w") or die("Unable to open file!"); //Open table structure file for
$myfiletemp = fopen($viewfile1, "r") or die("Unable to open file!"); //Open table structure file for
while(!feof($myfiletemp)) // Reading the table structure file
{
$line= fgets($myfiletemp) ;
$rtext=str_replace("HHHUUUPPP",$table,$line);
fwrite($myfilemain,$rtext);
}
fclose($myfilemain);
fclose($myfiletemp);
unlink($viewfile1);
?>
While dealing with template file, it is too common to make copies of that file and replace one word by another word.
In the code attached below one file is created dynamically based on table name and then a local copy of template file is created in the name of table in a folder HUP. Then a word HHHUUUPPP will be replaced with the name of table. Once the entire file is replaced then a fresh copy the new file will be taken and old file will be deleted.
//Code starts here.
<?php
$table=$_POST['tablename'];
$viewfile1='HUP/view'.$table.'1.php';
$viewfile='HUP/view'.$table.'.php';
copy('HUPViewtable.php',$viewfile1);
$myfilemain=fopen($viewfile, "w") or die("Unable to open file!"); //Open table structure file for
$myfiletemp = fopen($viewfile1, "r") or die("Unable to open file!"); //Open table structure file for
while(!feof($myfiletemp)) // Reading the table structure file
{
$line= fgets($myfiletemp) ;
$rtext=str_replace("HHHUUUPPP",$table,$line);
fwrite($myfilemain,$rtext);
}
fclose($myfilemain);
fclose($myfiletemp);
unlink($viewfile1);
?>