append to a php file
Posted: Wed Feb 21, 2007 4:09 pm
Hey guys. I am having trouble "replacing" a string in a php/text file. I've created an Update script that is supposed to update a previous php configuration script with my new one. The problem i am having is i cannot replace the ?> with a "" so i can append to the file, then later closing it with the ?> tag.
I know it's probably really easy to do, i just can't get my head over it.
I know it's probably really easy to do, i just can't get my head over it.
Code: Select all
// info that is to be added.
$updatedinfo = '
$text = "some config info";
...
?>';
// check if script exists.
$exist = fopen("configfile.php", "r");
if($exist)
{
$fp = fopen("configfile.php", "a");
$cfile = file("configfile.php");
foreach ($cfile as $line_num => $cfile)
{
ereg_replace("?>","",$cfile);
htmlspecialchars($cfile);
echo "<br />";
}
fwrite($fp, $cfile);
fclose();
} // end if.