0

I have created an array which contains;

  1. The filepath where the item is to be written.
  2. the contents that I wish to be written to the file

The code for my array is:

foreach ($NewLang as $row => $val)
{
    $writefile = implode(",", $val);

    $filepath = $val[0];
}

This will display something like this:

basket.lang.php,LANG_BASKETUPDATED,Basket Updated,

My question is how can I use file_put_contents() to write each line based on the value stored in $val[0]?

Jimbo
  • 25,790
  • 15
  • 86
  • 131
  • 7
    This question appears to be off-topic because it is about asking how to read [the manual](http://php.net/manual/en/function.file-put-contents.php) – HamZa Jul 04 '13 at 09:02
  • The filepath changes for each line, I can write it easily enough if the filepath is the same. – Philip Richardson Jul 04 '13 at 09:03

2 Answers2

0

Something like:

file_put_contents($filepath, $writefile); 

The content of $writefile would be written into the file that's name is inside $filepath

e.g.

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

This would write a file in you home path named 'output.txt' which will contain the 2 lines

This is

a test

Community
  • 1
  • 1
cb0
  • 8,415
  • 9
  • 52
  • 80
0

Solved this by creating a function for writing the files and placing it in the foreach loop instead.

Now my foreach loop looks like this:

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