PHP在文本文件中的两行之间添加行

I need to insert a line in a textfile between two other lines:

1: 30-12:32 1

2: 30-12:34 1

3: 30-12:35 1

For an example I need to insert a line between 1 and 2 which says 30-12:34 0. I have the code to calculate what needs to be inserted by looking at the previous number but I need help inserting the text. Thank you

Use this and then

function replaceInFile($what, $with, $file){
   $buffer = "";
   $fp = file($file);
   foreach($fp as $line){
      $buffer .= preg_replace("|".$what."[A-Za-z_.]*|", $what.$with, $line);
   }
   fclose($fp);
   echo $buffer;
   file_put_contents($file, $buffer);
}

and then enter what as the line just before it in text and with as what you want after it.