Miscellany
public text v1 · immutablefunction add_text_to_file($file, $text, $replace = false) {
if(file_exists($file) and is_writable($file)) {
$filecontents = file($file);
$fout = fopen($file, "w");
$filecontents = array_map('rtrim', $filecontents);
array_push($filecontents, $text);
if ($replace)
$filecontents = array_unique($filecontents);
$file_text = implode("\n", $filecontents);
fwrite($fout, $file_text);
fclose($fout);
return true;
} else {
return false;
}
}