Jump to content

export to excel file - arabic characters not displaying properly?


phpmady

Recommended Posts

Hi,

 

i have export the search result to excel file, but arabic characters not displaying properly in excel file, eventhough i mention the header content type as utf-8

 

here my code...

 

<?php
include("global.php");
// Original PHP code by Chirp Internet: www.chirp.com.au 
// Please acknowledge use of this code by including this header. 

function cleanData(&$str) 
{
$str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); 
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; 
} 

$sql = $_SESSION['emp_search_sql'];
// file name for download 
$filename = "employees_" . date('Ymd') . ".xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel; charset=UTF-8"); 
header("Pragma: no-cache";


$flag = false;
$result = $DB_site->query($sql) or die('Query failed!');
while(false !== ($row = mysql_fetch_assoc($result)))
{
if(!$flag) 
{
// display field/column names as first row 

echo implode("\t", array_keys($row)) . "\n"; $flag = true; 
} 
array_walk($row, 'cleanData'); 
echo implode("\t", array_values($row)) . "\n";
}

?>

 

 

Thanks,

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.