PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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?
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);
Ah ha got it again. All I did was set a variable called $success = "Yes"; if the line that started with my search string was found, then outside my loop, I array_push my new line only if $success was flase. Thanks again for the help: