【发布时间】:2012-11-30 16:59:34
【问题描述】:
我想使用 PHP 在文件中插入行,但从文件中的特定行开始。
我的文件 acme.yml 有一行 shortcuts:。我想在它前面插入几行。
#newlines here
shortcuts:
我在PHP手册中看到了file_get_contents和file_put_contents这两个函数,但不知道是不是最好的办法。
<?php
$file = 'acme.yml';
$newlines = array($line1, $line2, $line3);
$current = file_get_contents($file);
#TODO:
file_put_contents($file, $current);
?>
也许在 yml 文件中有更好的方法。
【问题讨论】: