Answer the question
In order to leave comments, you need to log in
Why problems with encoding when transferring to another server?
Good evening. Faced the following problem.
There are two servers. The two libraries used for outputting data to PDF and Excel are experiencing problems on one of them with the same code base. On the problem server, question marks and scribbles are output to the above file formats - by all indications of an encoding problem.
I believe it's in the database (Postgres). On the problematic server, the database parameters Collation and Character-type are en_US.UTF-8, and on the one where everything is in order - ru_RU.UTF-8.
Can anyone come across? If yes, how can this problem be solved?
Answer the question
In order to leave comments, you need to log in
Found the solution in the form ob_end_clean();
before setting the headers.
Until the end, I have not figured it out yet, but before that, strange things happened with the output. I debugged the code and the base turned out to be nothing to do with it at all. I manually registered the cells of the table and worked out one word in Russian successfully, while the other was not displayed in the same cell. Didn't find a connection.
If anyone can explain why ob_end_clean() helped, I would be grateful. Below is the working code. Cleaned up the excess.
require_once __DIR__ . '/../phpexcel/Classes/PHPExcel.php';
require_once(__DIR__ . '/../phpexcel/Classes/PHPExcel/Writer/Excel5.php');
$xls = new \PHPExcel();
$xls->setActiveSheetIndex(0);
$sheet = $xls->getActiveSheet();
$sheet->setCellValue("A1", 'Тест1');
$sheet->setCellValue("B1", 'Тест2');
$sheet->setCellValue("C1", 'Тест3');
$sheet->setCellValue("D1", 'Тест4');
$sheet->setCellValue("E1", 'Тест5');
$sheet->setCellValue("F1", 'Тест6');
$sheet->setCellValue("G1", 'Тест7');
$sheet->setCellValue("H1", 'Тест8');
ob_end_clean();
header ( "Expires: Mon, 1 Apr 1974 05:00:00 GMT" );
header ( "Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT" );
header ( "Cache-Control: no-cache, must-revalidate" );
header ( "Pragma: no-cache" );
header ( "Content-type: application/vnd.ms-excel" );
header ( "Content-Disposition: attachment; filename=test.xls" );
$objWriter = new \PHPExcel_Writer_Excel5($xls);
$objWriter->save('php://output');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question