<?php
$testfile = 'testfile';
// zeigt den aktuellen inhalt der datei
function showFileContent($file) {
static $step = 1;
$content = file_get_contents($file);
echo "<h2>Step: $step</h2><pre>$content</pre><hr />";
$step++;
}
file_put_contents($testfile, "asd\nasd\nasd");
showFileContent($testfile);
// zu ändernde zeile
$line = 2;
$suffix = ' ich werde angehängt';
$file = file($testfile);
$file[$line - 1] = trim($file[$line - 1], "\n\r") . $suffix . "\n";
file_put_contents($testfile, implode('', $file));
showFileContent($testfile);
?>