I wonder if you guys could help me with something. I have a text file which I use the following code to open a text file and append a line at the top.
$filename = $_SERVER["DOCUMENT_ROOT"]."/test.txt";
$content = "this is a test";
$handle = fopen($filename, 'r');
$content .= fread($handle,filesize($filename));
fclose($handle);
$handle = fopen($filename, 'w+');
fwrite($handle, $content,strlen($content));
fclose($handle);
Works fine. However I now need to insert the same line, but at a certain place in the text file. So say for example in the text line it contains a line "ABCD". I would want to insert my new line into the text file above the "ABCD" line.
I've tried a few things but haven't been able to get it to work. Can you help? Thanks :)