CSV导出&从codeigniter导入

时间:2016-10-16 13:31:22

标签: codeigniter csv

我使用codeigniter csv_from_result函数导出阿拉伯语内容,但是当我导入文件时,它不会读取阿拉伯语内容。

$data = chr(0xff) . chr(0xfe) . mb_convert_encoding($data, 'UTF-16LE', "auto");

我正在使用此代码导出阿拉伯语CSV:

export arabic content

csvimport library导入:

$csvdata = $this->csvimport->get_array($file);

它不能正常工作。

2 个答案:

答案 0 :(得分:0)

使用阿拉伯语内容导出csv

$table = 'test';
$this->load->dbutil();
$this->load->helper('file');
$this->load->helper('download');
$delimiter = "\t";
$newline = "\r\n";
$filename = $table . date('Y-m-d H:i:s') . ".csv";
$result = $this->db2->get($table);
$data = $this->dbutil->csv_from_result($result, $delimiter, $newline);
$data = chr(255) . chr(254) . mb_convert_encoding($data, 'UTF-16LE', 'UTF-8');
force_download($filename, $data);

然后导入

header('Content-Type: text/html; charset=utf-8');
$filename = 'test.csv';
$filename2='test2.csv';
file_put_contents($filename2, str_replace("\t", ";", iconv('UTF-16', 'UTF-8', file_get_contents($filename))));

$filehandle = fopen($filename2, 'r');
$data = array();

while (($csvdata = fgetcsv($filehandle, 1000, ";")) !== FALSE) {
    $data[] = $csvdata;
}

echo '<pre>';
print_r($data);
echo '</pre>';

答案 1 :(得分:-1)

    ini_set('max_execution_time', 0);
    ini_set('memory_limit','2048M');
    $this->db->select("id,Title,Description,Link,ImageLink as Image Link,GoogleProductCategory as Google Product Category,ProductType as Product Type,Conditionlabel as Condition,Availability,Brand,MPN,Price,Shipping,CustomLabel0,CustomLabel1,PromotionId");
    $query = $this->db->get('temp_csvexport');
    $this->load->helper('csv');

    query_to_csv($query, TRUE, 'file_name.csv');