如何在php的固定位置将文本添加到文件中


How to add text to file at fixed position php?

我有这个代码:

$new_news = '; array(
    ''img'' =>'.$path.',
    ''title'' => '.$_POST["title"].',
    ''text'' => '.$_POST["text"].'
)';

我需要将其添加到db.php中现有的数组中。例如:

$news = array(
    array(
    'img' => 'images/egle.jpg', 
    'title' => 'Egle pārtraukusi ',
    'text' => 'Valsts prezidenta Andra '));

如何使用fopen()添加长度为4的$new_news?

$new_news更改为数组,而不是字符串。

$new_news = array(
  'img'   => $path, 
  'title' => $_POST["title"],
  'text'  => $_POST["text"]
);
$news[] = $new_news;