Hello. My problem is that when I export a database. All Cyrillic Flies My Controller

public function export2() { $table = Order_products::all(); $filename = "test2.csv"; $handle = fopen($filename, 'w+'); fputcsv($handle, array('sep=,')); fputcsv($handle, array('name','phone')); foreach($table as $row) { fputcsv($handle, array($row['name'], $row['description'], $row['staticprice'])); } fclose($handle); $headers = array( 'Content-Type' => 'text/csv', ); return Response::download($filename, 'test.csv', $headers); } 

enter image description here

Help, pliz

  • open in OpenOffice.ORG - Farkhod Daniyarov

2 answers 2

Excel on windows understands only windows-1251 encoding, therefore you need to convert all your strings:

replace

 fputcsv($handle, array($row['name'], $row['description'], $row['staticprice'])); 

on

 fputcsv($handle, array(iconv('utf-8', 'windows-1251', $row['name']), iconv('utf-8', 'windows-1251', $row['description']), iconv('utf-8', 'windows-1251', $row['staticprice']))); 
     fprintf($handle, chr(0xEF).chr(0xBB).chr(0xBF)); 

    Add this line after fopen ()