根据数组值写入文件

时间:2013-07-04 09:01:03

标签: php fwrite

我创建了一个包含;

的数组
  1. 要写入项目的文件路径。
  2. 我希望写入文件的内容
  3. 我的数组的代码是:

    foreach ($NewLang as $row => $val)
    {
        $writefile = implode(",", $val);
    
        $filepath = $val[0];
    }
    

    这将显示如下内容:

      

    basket.lang.php,LANG_BASKETUPDATED,Basket Updated,

    我的问题是如何根据file_put_contents()中存储的值使用$val[0]来编写每一行?

2 个答案:

答案 0 :(得分:0)

类似的东西:

file_put_contents($filepath, $writefile); 

$ writefile的内容将被写入名称在$ filepath

中的文件中

e.g。

$writefile="This is\na test";
$filepath="~/output.txt";
file_put_contents($filepath, $writefile); 

这会在你的主路径中写一个名为'output.txt'的文件 其中包含2行

  

这是

     

测试

答案 1 :(得分:0)

通过创建一个函数来解决这个问题,该函数用于编写文件并将其放在foreach循环中。

现在我的foreach循环看起来像这样:

foreach ($NewLang as $row => $val)
{   
    {   
        append_define($val[0], $val[1], $val[2]);
    }
}