The following code supposed to add at the beginning of my php files on the webserver the string abcdef.
However it replaces all the content with the abcdef. How can I correct it?
Also how can I add something on the end instead of the beginning?
foreach (glob("*.php") as $file) {
$fh = fopen($file, 'c'); //Open file for writing, place pointer at start of file.
fwrite($fh, 'abcdef');
fclose($fh);
}
You just need to open the file with a flag that allows you to write without truncating the file to zero length: