How to append to an existing array?
Posted: Thu Sep 12, 2002 10:24 pm
Ok so I read my file into memory, then search for any line that starts with Counter and replace it with my new line. Works perfect. Now how in the code below can I specify that if I dont find any lines with that start with Counter then Append it to the end of the file?
Thanks in advance.... again
Thanks in advance.... again
Code: Select all
elseif (file_exists($htaccess)) {
//Read it in to and array
$file = file("$htaccess");
$count = 1;
$maxval = count($file);
while ( $count <= $maxval ){
//search for any line that starts with Counter
if ( ereg("Counter",$fileї$count]) ){
$fileї$count] = "$counter_syntax";
}
else
{
//I need to append $counter_syntax How?
}
$count++;
}
// To write to the file incase we found a line with Counter
$a1 = fopen("$htaccess", "w+");
flock($a1,2);
foreach ($file as $key){
$fw = fwrite($a1, $key);
}
//And we close again
fclose($a1);