Jump to content

[SOLVED] Replace Line


lalabored

Recommended Posts

I have a file named lala.php. I have a script to check if the first line is "lalala", if it isn't then it will replace it with "lalala". Then it will rewrite the new information back into lala.php. For some reason this doesn't work. It will simply replace the contents of the entire file with "lalala". I only want it to replace the first line with "lalala".

 

$fh = fopen("lala.php", "w") or die("Error: Cannot open file.");
$check = file("lala.php");
$lala = "lalala";

if($check[0] != $lala){
$check[0] = $lala;
$newcheck = implode("",$check);
fwrite($fh, $newcheck);
}

fclose($fh);

Link to comment
https://forums.phpfreaks.com/topic/50084-solved-replace-line/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.