2012-08-22 149 views
0

我有這樣的代碼:如何將文本添加到固定位置的文件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?

+0

你的意思是你只是想添加數組'$ new_news'到'$ news'嗎?另外,你的意思是長度爲4? – BenOfTheNorth

+0

使用array_merge,$ news []與$ new_news – amitchhajer

+0

我不明白,你是否真的試圖將數據存儲在.php文件中的數組? – hndr

回答

2

$new_news更改爲數組,而不是字符串。

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

$news[] = $new_news; 
+0

我需要將此添加到文件..不是陣列.. –

+0

@AigarsCibuļskis,你有沒有嘗試http://php.net/manual/en/function.fwrite.php – tomexsans

相關問題