I would like to insert lines into a file using PHP but from a specific line in the file.
My file acme.yml has a line shortcuts:. I want to insert some lines before it.
#newlines here
shortcuts:
I saw the functions file_get_contents and file_put_contents in the PHP Manual, but I don’t know if it is the best approach.
<?php
$file = 'acme.yml';
$newlines = array($line1, $line2, $line3);
$current = file_get_contents($file);
#TODO:
file_put_contents($file, $current);
?>
Maybe there are a better way to do it in yml files.
Try this.