2012-08-22 42 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

相关问题