如何使用另一个从数组中获取值的codeigniter php脚本写入php脚本? [关闭]

I am trying to write variables in the language library in codeigniter. I got the value in a csv file, so I read the csv file and take the value in an array. Now I am trying to write these array values in the language library. for example inside language>english folder I have a script called english.php. Now I want to write constant values from that array in this file.Thanks in advance

You just want to write in a file, right?

If you have correct permissions, you can do the following:

file_put_contents($myLanguageFile, '<?php ' . var_export($myCsvArray, TRUE));

It will fill you language file with correct PHP code.

To write CSV content to file you should use fputcsv()

 fputcsv — Format line as CSV and write to file pointer

Example from manual:

$list = array (
array('aaa', 'bbb', 'ccc', 'dddd'),
array('123', '456', '789'),
array('"aaa"', '"bbb"')
);

$fp = fopen('file.csv', 'w');

foreach ($list as $fields) {
    fputcsv($fp, $fields);
}

fclose($fp);

OUTPUT:

aaa,bbb,ccc,dddd
123,456,789
"""aaa""","""bbb"""
consider CSV file contains(file name test.csv)

drink,Drink
enable_on,Enable On
message_drink_saved,The drink has been saved!


<?php
$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {

    $string = "<?php ";

    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {

       $string=$string "$lang['".$data[0]."'] = '".data[1]."';"

    }
    fclose($handle);
}


$fp = fopen("language.php", "w");

fwrite($fp, $string);

fclose($fp);

?>