10-09-2008, 08:52 AM
|
#1 (permalink)
|
|
The Contributor
Join Date: Oct 2008
Location: UK
Posts: 30
Thanks: 0
|
Adding content to a specific line in file
I'm relatively new to PHP so bare with me.I'm trying to replace a specific line to a file. This is my code so far:
PHP Code:
$string = "Blah blah blah
<!-- comment -->";
$file = fopen("file.txt", "r"); // Open file
if($file){
while(!feof($file)){ // Before end of file
$read = fgets($file, 1000); // read line
if ($read=="<!-- comment -->"){ // if right line
$read = $string; // change to variable
}}
fclose($file);
}
I'm unable to test this at the moment, so if someone could check this and/or suggest anything better that would be helpful.
Cheers.
|
|
|
|